CLOUD RIP MOUNTAIN: "Timber Guard" (Python)

Puzzle’s Location


My code structure:

My hero does the following (sections):

  1. Collects gold (until having 20).
  2. Moves to the center of the map {"x":56, "y":45} (if hero’s gold >= 20)
  3. Summons a “soldier” (if hero’s gold >= 20)
  4. Commands the soldier to move to the right of the map {"x":83,"y":45}
  5. If there is a near enemy, commands the soldier to attack the enemy until the enemy dies

The problem:

I’ve run the code section by section and all work fine except the while loop in the last section, it’s running forever!


Also, my minions don’t move/attack unless the location {“x”:56, “y”:45}/enemy is within my hero’s eye-sight.

    enemy = hero.findNearestEnemy()
    for soldier in hero.findByType("soldier", hero.findFriends()):
        hero.command(soldier, "move", {"x":88, "y":47})
        if enemy:
            while > 0:
                hero.command(soldier, "attack", enemy)

Any thoughts? :thinking:

1 Like

Go ahead and remove the while loop for the enemy health. Since you are continuously commanding them to attack there is no need to add the while loop.

  1. Moves to the center of the map {"x":56, "y":45} (if hero’s gold >= 20)

I think the second problem may be linked to moving your hero to {“x”: 56, “y”: 46}. There isn’t a need to move the hero to summon your soldier. If you are using the moveXY in that section then the rest of your code won’t run until your hero reaches that point, including commanding your minions to move/attack.

Now it works fine :smiley: