Zoo Keeper python Help!😺

This is the code:

# Protect the cage.
# Put a soldier at each X.
points = []
points[0] = {"x": 33, "y": 42}
points[1] = {"x": 47, "y": 42}
points[2] = {"x": 33, "y": 26}
points[3] = {"x": 47, "y": 26}

# 1. Collect 80 gold.
while hero.gold < 80:
    hero.move(hero.findNearest(hero.findItems()).pos)
# 2. Build 4 soldiers.
for i in range(4):
    hero.summon("soldier")
    
# 3. Send your soldiers into position.
while True:
    friends = hero.findFriends()
    for j in range(len(friends)):
        point = points[j]
        friend = friends[j]
        enemy = friend.findNearestEnemy()
        if enemy and enemy.team == "ogres" and friend.distanceTo(enemy) < 5:
            # Command friend to attack.
            hero.command(friend, "attack", enemy)
            pass
            
        else:
            # Command friend to move to point.
            hero.command(friends[j], "move", {"x":47, "y":26})
            pass
            

Is there anything wrong here? The soldiers will only fight(no damage) to get to 47, 26.

Good
You can remove the pass

No, I still can’t pass the level, here’s the code that ya said:

# Protect the cage.
# Put a soldier at each X.

points = []
points[0] = {"x": 33, "y": 42}
points[1] = {"x": 47, "y": 42}
points[2] = {"x": 33, "y": 26}
points[3] = {"x": 47, "y": 26}
# 1. Collect 80 gold.
while hero.gold < 80:
    hero.move(hero.findNearest(hero.findItems()).pos)
# 2. Build 4 soldiers.
for i in range(4):
    hero.summon("soldier")
# 3. Send your soldiers into position.
while True:
    friends = hero.findFriends()
    for j in range(len(friends)):
        point = points[j]
        friend = friends[j]
        enemy = friend.findNearestEnemy()
        if enemy and enemy.team == "ogres" and friend.distanceTo(enemy) < 5:
            # Command friend to attack.
            hero.command(friend, "attack", enemy)
        else:
            # Command friend to move to point.
            hero.command(friends[j], "move", {"x":47, "y":26})

This is the code that is without the pass.
**


**

Your last line

hero.command(friends[j], "move", {"x":47, "y":26})

Change to

hero.command(friend, "move", point)


that’s it

it works!!! thx謝謝 , level completed

Then just click the solution

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.