Timber turncoat help!

The soldiers I summon are too slow, causing the ogres to kill the peasant faster that the soldier can reach. Soldiers have small amounts of health; means that the warlock will appear faster. I am now trying my smartest strategy:
connecting the if statement is:. The reason why I did the screenshots is because I didn’t want to type out all that code again.

Two tips:

Do you know the difference between move and moveXY? Try to find out which should be used in this situation. Read the topics in this forum to find out about the differences between the two. Remember there is a search-function.

Monitor the health of your soldiers. If it is too low, send them back so they don’t die. Check friend.health < friend.maxHealth (or a similar value, I wouldn’t use this 1-to-1).

I know the diff between move an moveXY. Move moves one step at a time. So you can track your target. MoveXY gets 1 target but won’t do anything else until it is gone; not good for tracking your target.

This is what happened in
post1
:
In the screenshot, it showed that the soldiers were still trying to get to the ogre but it was too late.

Are you sending the soldiers out as soon as you summon them?

Do you summon the first soldier as soon as possible, that is at level start?
Or do you summon it maybe a bit later, because you are first using a blocking moveXY-command?

I already asked you if you know the difference and what it means.

right but you are forgetting the fact that you will loop through all the other functions before taking the next step so it is beneficial in almost all situations except a few

I just could win it with griffin riders, but with them very easy lol

Yes but at this point you might not have Griffin riders

My code is below, I can’t really see where I am going wrong, the ogres will always overwhelm my soldiers to the point that one will die and boom, trouble! Any thoughts?

                self.command(friend, "move", {"x": 11, "y": 45})

                self.command(friend, "move", {"x": 93, "y": 45})

I removed the other lines 'cause your code is good. :smiley:

I would suggest changing the remaining two lines.

The first one (x 11, y 45) is your “retreat if low health” position, and an ‘x’ of ‘11’ is inside the coin area at that location the hurt soldiers could get in your way collecting coins. Make ‘x’ say ‘30’ then they are out of the way for both you and your healthy soldiers.

The second one is very far out there . . . it takes a long time for the new soldiers to walk all the way out to 93 to help the old ones. “lowering” this to even 80, should make a big difference in when your reinforcements arrive to relieve the previous crew.

2 Likes

Thanks for the advice, combined with a fresh seed, this worked a treat.

Yeah. I am. The only problem is, that soldiers are way too slow.

It is impossible to solve this level with soldiers.
Archers are solution.

1 Like

You might not want to call the soldiers out of the battle so early. Try 50 health instead of 100 health. This will work with soldiers.

For my soldiers, they respond to the other commands to move and attack, but they don’t understand that they have to retreat? Why are they not retreating?

while True:
    # Collect gold.
    item = hero.findNearestItem()
    if item:
        hero.moveXY(item.pos.x, item.pos.y)
    # If you have enough gold, summon a soldier.
    if hero.gold >= 20:
        hero.summon("soldier")
    # Use a for-loop to command each soldier.
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "soldier":
            enemy = friend.findNearestEnemy()
            # If there's an enemy, command her to attack.
            # Careful! If your soldiers are defeated, a warlock will appear!
            # Otherwise, move her to the right side of the map.
            if friend.health < 100:
                hero.command(friend, "move", {'x':30, 'y':42})
            if enemy:
                hero.command(friend, "attack", enemy)
            else:
                hero.command(friend, "move", {'x':81, 'y':44})

Using stacked if statements, you are:

  • commanding any with less than 100 health to withdraw, but
  • you then command them to attack, or else retreat if there is no enemy…there is no condition set for state of health

It would be better to use a nested if/elif/else statement here.

Rather than concentrating on preserving your soldiers, I’d recommend using them to their fullest.

On a side note, I decided to use archers for this level…just a thought :wink:

1 Like

Thank you! I rearranged my commands and was able to complete the level!

1 Like

Well done! Please mark this topic as solved…if need help with that, let me know.

Because I am unsure about how many topics as I can make at contributor level 1, I reused this topic to ask for help, so I can’t mark it as solved. At trust level 1, do I get infinite replies and topics?
Thank you!