Arrgh! Identifying enemy types in Harrowland


#1

Ok, I have beat the level, but my code is not performing as expected. There are four types of enemies, and a total nine enemies. 1 - Ogre Hero, 2 - sand-yaks, 2 - archers, 4 - soldiers. I confirmed this enemy types with:

enemies = self.findEnemies

for next in enemies:
self.say(next.type)

The code returned Knight, sand-yak, archer and soldier though not in that order.

I have tried several sorting strategies to attack the soldiers, but my Hero always ignores them. I tried sorting with ‘soldiers’ and I tried sorting with exclusoin. The exclusion code is listed below. Why is my code ignoring the soldiers?

# Use your cleverest programming tricks to outwit and overpower your opponent!
enemies = self.findEnemies()
archers = []
others = []
booger = None

    
for enemy in enemies:
    if enemy.type is 'archer':
        archers.append(enemy)
    # This should have create an array with 6 elements - 2 archers and 4 soldiers.
    elif enemy.type is not 'sand-yak' and enemy.id is not "Hero Placeholder 1":
        others.append(enemy)
    elif enemy.id is "Hero Placeholder 1":
        booger = enemy

for next in archers:
    while next.health > 0:
        self. attack(next)

        
for next in others:        
    while next.health > 0:
        self.attack(next)

        
if booger:
    while booger.health > 0:
        self.attack(booger)
        
self.say("I picked my Booger")


#2

Well, does your hero finish attacking and killing all of the archers? Your code states that your hero must kill the archers before attacking the soldiers.


#3

He kills the archers then he attacks the knight. He ignores the sand-yaks, as he should, and he ignores the soldiers. Actually, I am assuming they are are soldiers even though they look like little archers for two reasons. 1) The sort for archer skips them and 2) my code reports that I have got an enemy.type of soldier.


#4

I got it to work if I put it all in a loop and changed your attacking statements to:

if len(archers):
    enemy = findNearest(archers)
    self.attack(enemy)
elif len(others):
   do stuff here

you can check to see if a list is empty by using if len(archers) or if archers[0]

You will still need to command your archers to win the level though.

Also:
There was something fishy going with sorting algorithm as it was only returning lists with a length of 2, even though I could see more than 2 archers, soldiers, ect and had glasses with infinite see distance. I am going to blame the compiler or enemies appearing a split second after the start of the level.


#5

In a lot of levels the enemies only appear in the second game frame. Use a wait() or a move of 0.1m to make your hero wait a bit, then read the enemies

Putting everything inside the loop as Hinkle suggested is even better


#6

Hey Hinkle,

Thank you very much for the help. You’ve stated that I still need to command my archers to win this level, so I posted my question about command. Do I have to earn the Boss Star before I can win this level?

Thanks,
George


#7

No, but commanding (and summoning) help a lot. You also use your special abilities. Bashing works well.

If fact, you can beat the level with a ranger just by unequipping all your armor and throwing something at the enemy hero. Note that this will probably give you a bad score in the rankings though.