Stuck in Grim Determination

Hi all. I’m stuck on the level Grim Determination in the mountain levels. My most region is to ramp up a couple of peasants in the beginning, and then to give each one a ‘zone’ where they’re collecting coins, in order to maximize collection. I’ve tweaked my strategy with the rest of the level to the point that I think I’ve got it, if not for the problem that I can’t figure out why only the first peasant does anything. Here’s my code:

# Here's the first two CommandPeasant functions; there are 4 in total
def commandPeasant1(psnt):
    hero.command(psnt, "move", {"x": 35, "y": 24})
    coins = psnt.findItems()
    for coin in coins:
        if coin.value >= 3 and coin.pos.x > 23 and coin.pos.y < 39:
            hero.command(psnt, "move", coin.pos)
            break

def commandPeasant2(psnt):
    hero.command(psnt, "move", {"x": 35, "y": 55})
    coins = psnt.findItems()
    for coin in coins:
        if coin.value >= 3 and coin.pos.x > 23 and coin.pos.y > 38:
            hero.command(psnt, "move", coin.pos)
            break

# And now, in CommandFriends():
def commandFriends():
    # Command your friends.
    friends = hero.findFriends()
    peasants = hero.findByType("peasants")
    for friend in friends:
        if friend == peasants[0]:
            commandPeasant1(friend)
        elif friend == peasants[1]:
            commandPeasant2(friend)
        elif friend == peasants[2]:
            commandPeasant3(friend)
        elif friend == peasants[3]:
            commandPeasant4(friend)
        elif friend.type == "griffin-rider":
            commandGriffin(friend)
        elif friend.type == "paladin":
            commandPaladin(friend)

# And now, the relevant part of the loop:
while True:
commandFriends()

With this code, the lower of the two peasants (I believe she’s always ‘Rose’) goes about collecting (as does the Mimic, who’s running from a different function), but Hector and any summoned peasants never even so much as move.

Any help, or even general advice on strategy would be greatly appreciated.

Whoops! I figured it out myself. I had put hero.findByType("peasants") with peasants in the plural. I got it by debugging by having the hero say the peasants list, and it was empty. (Not sure why the first peasant was still collecting…) Now they’re all doing their thing with hero.findByType("peasant").

But I’m still not winning… :anguished:

2 peasants are really enough. I split up the coin field into two, and one peasant was assigned to each field.

Splitting the field into two
while True:
    coins = {"top": [], "bottom": []}
    for item in hero.findItems():
        if item.pos.y > 38:
            coins.top.append(item)
        else:
            coins.bottom.append(item)
    # ...

Then, using a simple check of the peasant’s y-position, I can figure out which peasant uses which coin array to collect coins with.

def commandPeasant(peasant):
    if peasant.pos.y > 38:
        hero.command(peasant, "move", findBestCoin(peasant, coins.top).pos)
    else:
        hero.command(peasant, "move", findBestCoin(peasant, coins.bottom).pos)

Never defined commandPeasant3(friend) or commandPeasant4(friend)

He didn’t post all of his code.

@byobcello I discovered the hard way that four peasants doesn’t increase the total loot, and switched back to 2.

Tweaking the code on the paladins was what made the difference in the end.

I’m enjoying just reading your code, though. That’s a really great way to do it. I never thought of making a dictionary of lists like that.