Summit's Gate Stuck after killing the two towers it goes on a loop walking straight


#1

After a couple of months trying different things, just now I’ve killed the two towers twice on a row, in nearly 40 seconds; then my flag does no longer work, Aryn no longer obeys my flag and just walks straigth on a loop; the making of new griffin-riders does no longer work, etc. Besides, Aryn gets frozen more than 75% of the time. The flag no longer works, and I’ve tried passsing this more than 50 times. My code is more than enough to get passed Summit’s Gate. I’ve gotten to the very end killing all but the beam towers to avoid getting FROOOOOZZZZEEENNN over and over and over and over and over again; and got frozen when I came back to take the towers. Is this game supposed to work like this?

My code works really well so I don’t know if I can post it here. On the other hand, I don’t know what else to do.


#2

OK, here goes my code…

// Fight your way into the Inner Sanctum of the ogre chieftain, and kill her.
this.commandPaladin = function(paladin) {
    var nearestEnemy = paladin.findNearest(this.findEnemies());
    var paladinX = paladin.pos.x;
    var paladinY = paladin.pos.y;
    var paladinSecure1 = (115, 47);
    var paladinSecure2 = (117, 22);
    if (paladin.canCast("heal")) {
        this.command(paladin, "cast", "heal", this);
    }
    else if (paladin.health < paladin.maxHealth /3) {
        this.command(paladin, "shield");
    }    
    else if (nearestEnemy) {
        this.command(paladin, "attack", nearestEnemy);
    }
    else if (paladin.pos.x > 103 && paladin.pos.x < 150) {
        this.command(paladin, "move", paladinSecure1);
    }
    else {
        this.command(paladin, "move", this.pos);
    }
};

this.commandFighter = function(amigo) {
    var enemy = amigo.findNearestEnemy();
    if (enemy) {
        this.command(amigo, "attack", enemy);
    }
};

this.summonGriffin = function(){
    if (this.gold >= this.costOf("griffin-rider")) {
        this.summon("griffin-rider");
    }
};

this.commandFriends = function() {
    var friends = this.findFriends();
    for(var i=0; i < friends.length; i++) {
        var friend = friends[i];
        if (friend.type === "archer" || friend.type === "griffin-rider") {
            this.commandFighter(friend);
        } else if (friend.type === "paladin") {
            this.commandPaladin(friend);
        }
    }
};

loop {
    var flagViolet = this.findFlag("violet");
    var flagBlack = this.findFlag("black");
    if (flagViolet) {
        this.pickUpFlag(flagViolet);
        var violetX = this.pos.x;
        var violetY = this.pos.y;
        this.moveXY(violetX, violetY);
        this.warcry();
    }
    this.commandFriends();
    this.summonGriffin();
    var enemy = this.findNearest(this.findEnemies());
    var tower = this.findByType("tower");
    var meX = this.pos.x;
    var meY = this.pos.y;
    if (enemy) {
        if (this.isReady("throw") && this.distanceTo(enemy) < this.throwRange) {
            this.throw(enemy);
            }
        else if (this.isReady("chain-lightning")) {
            this.cast("chain-lightning", enemy);
        }
        else if (this.isReady("cleave")) {
            this.cleave(enemy);
        }
        else {
            this.attack(enemy);
            this.bash(enemy);
        }
    }
    var friends = this.findFriends();
    for (var j = 0; j < friends.length; j++) {
        var friend = friends[j];
        if (friend.type == "griffin-rider") {
            this.command (friend, "defend", this); }
        if (friend.type == "skeleton") {
            this.command (friend, "defend", this); }
    }
}



#3

If there is a lot of computation, the code will get laggy and the flags will not respond.
Besides, you cannot trust flags too much because they are produced by humans. Humans are weak and they will mess the flags on the next play. Machines are strong and they will conquer all in due time :slightly_smiling:

Hard code your flags: once you find that a order works, hard-code it so you will not have to put that flag again:

// these tell you at what phase you are inside the level
var level_phase=0;
var next_flag=0;
// once you find that works, edit your code and put it automatically
var flags=[ {x:10,y:20}, {x:30,y:50},{x:100,y:50}];
 //this is your coded flag
var red_flag=false;
var red_flag_pos=null;

//this function is the "brain" of the level. 
//takes care of everything that is level specific
this.levelPlan = function(level_phase, next_flag){
    // decide when to throw the next flag:
    if(catapults.length==0) //all enemies killed
    if(this.now()>35) // some time passed
    if(this.distanceTo(warlock)) //near a enemy
    if(tower.health<0) // some enemy is dead
    // combine this with level_phase also:
   if(level_phase==0 && catapults.length==0){
          level_phase++;
          enemy=this.findNearest(this.findByType("door"));
          red_flag=true;
          red_flag_pos=flags[next_flag];
          next_flag++;
..................
};

and in the main loop:

if (red_flag){
     this.moveXY(red_flag_pos.x, red_flag_pos.y);
     // "pick up" the red flag
    red_flag=false;
}

Disclaimer: this code is written in 5 minutes, and not tested :stuck_out_tongue:


#4

I am really interested in this. But I don’t quite understand how it works.
Could you flesh out a bit? Here is how I translated this into python:

levelPhase = 0
flagindex = 0
# an array of wayward points
flags={}
# have we arrived at this flag?
flagCleared= False
#nextFlag stores the coordinats of your flag
nextFlag = null

def levelPlan (levelPhase, flagIndex):
	if len(catapults) == 0:
		pass
	if self.now()>35:
		pass
	if self.distanceTo(warlock):
		pass
	if tower.health <0:
		pass
	# this means we are ready to take down the door
	if levelPhase==0 and len(catapults) == 0:
		levelPhase+=1
		door = self.findNearest(self.findByType("door"))
		flagCleared = False
		flagIndex +=1
		nextFlag = flags[flagindex]
		


while levelPhase<4:

	levelPlan (levelPhase, flagIndex)
	if not flagCleared:
		self.moveXY(nextFlag.x, nextFlag.y)
		flagCleared=True
	
	levelPhase+=1