Mad Maxer: Redemption Time runs out


#1

My code calls all of the friends back home but, the time when the last one is called does not give it enough time to get back to the base and the last ogre to get killed. Is there an issue with the code or is this a bug?

Code is in Javascript.
while (true) {

**    var weakestFriend = null;**
**    var leastHealth = 9999;**
**    var friendIndex = 0;**
**    // Find which friend has the lowest health.**
**    var friends = hero.findFriends();**
**    while (friendIndex < friends.length) {**
**        var friend = friends[friendIndex];**
**        if (friend.health < leastHealth && friend.health != 30) {**
**            leastHealth = friend.health;**
**            weakestFriend = friend;**
**        }**
**        friendIndex += 1;**
**    }**
**    // Tell the weakest friends to go home first.**
**    if (weakestFriend) {**
**        hero.say("Hey " + weakestFriend.id + ", go home!");**
**    }**
**}**

#2

I suggest use

friend.type == "peasant"

instead

friend.health != 30

friend.health != 30 - is too strict
if archer take any damage hero will calling him
Until health of the peasant not drop lower than archer
And it is lower than 30
So level for sure going to end faster
Than ogre do enought damage for
weakestFriend variable take peasant instead of archer

You should also take into accaunt
hero.say takes 7 seconds for this level.


#3

Thank you. I was wondering why it was taking so long between hero.say’s.

So then, should I put the if (friend.health < leastHealth) in an if (friend.type == “peasant”) statement?


#4
if (friend.health < leastHealth && friend.type == "peasant" )

Or you can do it another way

var friends = hero.findByType( "peasant" )

This give you array with peasants only.


#5

Did you make a mistake on id


#6

By using weakestFriend.id it says the peasant’s name. Was there another way to say the peasant’s name? Thanks for the help.:smile:


#7

Thank you. I didn’t even think about the findByType function.


#8

Click on the peasant and it should give the peasants name


#9

#Find which friend has the lowest health.

umm… how do I do this?


#10

You pretty much run through every friend and compare their health.
Here’s a similar instance that compares the number of apples on the trees in an apple tree grove.

trees = farmer.findTrees()
treeIndex = 0
lowAppleCount = 99999
lowTree = None
while treeIndex < len(trees):
    tree = trees[treeIndex]
    if tree.appleCount < lowAppleCount:
        lowAppleCount = tree.appleCount
        lowTree = tree
    treeIndex += 1

farmer.say(lowTree + " has the least apples.")