[SOLVED]Reindeer Tender Help Please

Hi people of Codecombat :stuck_out_tongue:,
I’m stuck on Reindeer Tender.
It’s on Cloudrip mountain.
The link: # http://codecombat.com/play/level/reindeer-tender
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.
assignments = [ 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
            assignments[posIndex] = penPositions[posIndex]
            # Remove the reindeer from the friends array.
            friends[deerIndex] = None
            # break out of the inner loop here:

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

It says incomplete.
The problem is that the reindeer go to the pens that are preocuppied.

Try changing this to

assignments[posIndex] = reindeer.id

Other than that your code looks OK (hopefully!).


1 Like

Replace with:

for posIndex in range(len(penOccupants)):

The comment above this line says:

# Look for the first pen with nothing.
1 Like

Got the same result :frowning:

It says this look:

@jka2706 and @FalconX11_312 It does not work. :frowning: :thinking: I still do not know what is wrong! It is frustrating! I am feeling :face_with_symbols_over_mouth:

Haha no worries I beat the level! :laughing: :partying_face:

1 Like

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