Summits gate rush


#1

On summits gate, my soldiers are attacking, but not following my orders! This is my code:

# Fight your way into the Inner Sanctum of the ogre chieftain.

soldiers=self.findByType("soldier")
catapults=self.findByType("catapult")
for i in range(2):
    soldier=soldiers[i]
    catapult=catapults[i]
    self.command(soldier, "attack", catapult)
    


#2

You have more than two soldiers. Find a way to split them into two groups

for soldier in soliders:
     i=choseCatapultToAttack(solider,catapults)
     self.command(solider,"attack", catapults[i])

If you just make i=0 then all of them will attack the same catapult.

Finally, make sure you are giving them only one order per main loop


#3

i solved it without commanding just flags


#4

I only want one soldier to attack each catapult and I don’t want anybody else to do anything.


#5

well i just did nothing and the soldiers archers and the paladins automatically walked to the catapult while pushing enemies
and the catapult killed itself :slightly_smiling:


#6

Then everyone dies! I want nobody to move unless I command them.


#7

ya thats the whole point you want them to die so the paladins at the end dont go all the way to heal them


#8

No, I want them to survive. How do I get them to attack the catapults?


#9
  1. If your archers walk behind the soldiers they will be blown apart or killed easily. Command them to move near your hero

  2. If you soldiers stick around after attacking the catapult, the last catapult fireball will land on them. Command them to move in front of the gate if:

    • flag
    • OR catapult dead
    • or time

#10

I want only one soldier to attack each catapult! My code should do that, but it doesn’t.


#11
catapults=this.findByType("catapult");
allies=this.findFriends();
soldier1=allies[0];
loop{

// Some more code here

if (catapults[0].health>0)
     this.command(soldier1,"attack",catapults[0]);
}

If allies[0] does not happen to be the solider you wanted, change 0 to another number, or use findByType and allies[i].pos to select the best soldier


#12

I did that. It still doesn’t work! Here is my code:

# Fight your way into the Inner Sanctum of the ogre chieftain, and kill her.
catapults=self.findByType("catapult")
allies=self.findFriends()
soldier1=allies[0]
for friend in self.findFriends():
    if friend:
        self.command(friend, "defend", friend.pos)
loop:
    for paladin in self.findByType("paladin"):
        self.command(paladin, "move", self.pos)
        if paladin.canCast("heal", self) and self.maxHealth-self.health>100:
            self.command(paladin, "cast","heal", self)
    if catapults[0]:
        self.command(soldier1,"attack",catapults[0])
    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    if enemy and enemy.type != "door":
        self.attack(enemy)


#13

There are a few problems with your code:
1.It seems that allies[0] is a archer and it will get killed instantly
2. “defend” does not usually work. It instructs the ally to attack anyone that comes near its position. But when the solider attack, it changes position, so it will attack anyone near its new position and so on.
3. Sending only one soldier for the catapults will get him killed instantly send a group.

Here is a very simple code that works- in the sense that everyone dies :stuck_out_tongue:

You can improve it if

  • you split your soldiers into two group
  • you instruct them to run away if the catapult is dead or nearly dead (otherwise the last catapult shot will land on both the catapult itself and on your soldiers).

In the code some of the soldiers escaped the 1st catapult’s dying shot but it could have been better if they would have left a bit earlier

Dumb code
soldiers=self.findByType("soldier")    
loop:
    catapults=self.findByType("catapult")
    allies=self.findFriends()
    for ally in allies:
        self.command(ally,"move",self.pos)
    if catapults[0]:
        for soldier in soldiers:
            self.command(soldier,"attack",catapults[0])
    self.move(self.pos)