[SOLVED] HELP! Reindeer Tender

Hi… I know that um…

But I have a different problem.

Here is my code:

# This is the array of pen positions
penPositions = [ {"x":20,"y":24}, {"x":28,"y":24}, {"x":36,"y":24}, {"x":44,"y":24}, {"x":52,"y":24} ]

# Use this array to keep track of each pen's reindeer.
penOccupants = [ None, None, None, None, None, ]

# And this array contains our reindeer.
friends = hero.findFriends()

# Figure out which reindeer are already in their pens.
for deerIndex in range(len(friends)):
    reindeer = friends[deerIndex]
    
    # For each position check if it matches a reindeer.
    for penIndex in range(len(penPositions)):
        penPos = penPositions[penIndex]
        
        if penPos.x == reindeer.pos.x and penPos.y == reindeer.pos.y:
            # Put the reindeer in occupants at penIndex
            penOccupants[penIndex] = reindeer
            # Remove the reindeer from the friends array.
            friends[reindeer] = None
            # break out of the inner loop here:
            break
            pass

# Assign the remaining reindeer to new positions.
for deerIndex in range(len(friends)):
    # If the reindeer is null, use continue:
    if not deerIndex:
        continue
    
    # Look for the first pen with nothing.
    for occIndex in range(len(penOccupants)):
        # If there is nothing, the pen is open:
        if not penOccupants[occIndex]:
            # Put the reindeer in the occupants array.
            occupants[occIndex] = friends[deerIndex]
            # Command the reindeer to move to the pen.
            hero.command(friends[deerIndex], "move", target)
            # break out early so we don't reassign:
            break
            pass

What’s happening is that the reindeer-
Don’t do anything.

Help would be appreciated,

@MarmiteOnToast

1 Like

:slight_smile: I can wait

Chars are made of grain and dairy

1 Like

I found a few mistakes:
In the first for,

You should remove the reindeer from the friends array (which is deerIndex), so it should be friends[deerIndex]=None.

Here, you should add the reindeer in the occupants array, and here, you should use what you did in the first fors, the occupants[occIndex] should become a reindeer, which is occupants[occIndex] = reindeer.
And the final mistake, is here:

Where do you command the reindeer move? Try to think of this yourself.

And sorry for the late reply.

3 Likes

Thanks, I’ll try it.

Thanks, I’ll try it.

Ah… I reset the code and forgot to change that :melting_face:

Same here :slight_smile:

2 Likes

I know this is off-topic, but Marmite’s been on discourse longer than I have… soo I think he knows to mark it :]

1 Like

Sorry everyone. I’ve been away recently and so I’ve not been active enough to test it. I should be able to today though. Thanks for the reminders, and @moonwatcher348, I’ve not been active on the discourse longer than you :slight_smile:

2 Likes

Thanks, it worked really well. While inputting the position I used deerIndex for the first attempt, which didn’t work, but after changing it everything was fine.

1 Like


Yeah… turns out something was wrong with my code again :grimacing:

Any ideas?

1 Like

Here is the mistake. It should be the unit, not the index.
Answer: friends[deerIndex]

2 Likes

I tried it (without looking at the answer), and submitted it this time, and now it works,

Thanks again,

@MarmiteOnToast

2 Likes

Oh xD. I had just changed it, but forgot to save it.

2 Likes

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