[SOLVED] Reindeer tender trouble

soi am doing reindeer Tender but thir is a strang error
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.id
            # Remove the reindeer from the friends array.
            friends[penIndex] = 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:
    reindeer = friends[deerIndex]
    if friends[deerIndex] == None:
        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.
            penOccupants[occIndex] = reindeer.id
            # Command the reindeer to move to the pen.
            hero.say(reindeer.id + penPositions[occIndex])
            # break out early so we don't reassign:
            break
            pass

the error:

i know you’re not supposed to do this, but will it work if you check for the reindeer before checking it’s pos.x and pos.y?

it does not give me the error any more my hero just say the name of a reinderr and then [object Object]

hmmm, lemme check my own code but remove what i told you to add because i think it will break your code

i removed it (20 chars)

i remeber having this problem the first time i did reindeer tender, but i forgot how i fixed it

im dumbfounded β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž β€Ž

try checking for the reindeer again, and instead of doing hero.say(reindeer.id + penPositions[occIndex]), actually command them like a soldier with hero.command()

1 Like

my new 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.id
            # Remove the reindeer from the friends array.
            friends[penIndex] = 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:
    reindeer = friends[deerIndex]
    if friends[deerIndex] == None:
        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.
            penOccupants[occIndex] = reindeer.id
            # Command the reindeer to move to the pen.
            hero.command(reindeer, "move", penPositions[occIndex])
            # break out early so we don't reassign:
            break
            pass

the moved in the code window but when i submited it gave me the same error and acted like it did not know what reindeer pos is

try again, maybe some seeds are bad

:melting_face: This took a while:
On line 22 friends[penIndex] needs to be friends[deerIndex]. Otherwise It deletes the reindeer based on the pen positions array instead of the deer array.

That also explains why there was only one seed that worked for me :sweat_smile: because the penIndex and deerIndex lined up perfectly.

my new 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 == reindeer.pos:
            # Put the reindeer in occupants at penIndex
            penOccupants[penIndex] = reindeer.id
            # Remove the reindeer from the friends array.
            friends[deerIndex] = 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:
    reindeer = friends[deerIndex]
    if friends[deerIndex] == None:
        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.
            penOccupants[occIndex] = reindeer.id
            # Command the reindeer to move to the pen.
            hero.command(reindeer, "move", penPositions[occIndex])
            # break out early so we don't reassign:
            break
            pass


my hero is now commanding sleeping deer

i changed if penPos == reindeer.pos: to if penPos.x == reindeer.pos.x and penPos.y == reindeer.pos.y: and it worked

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