# \[SOLVED\] Reindeer tender trouble

**URL:** <https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810>\
**Category:** Level Help\
**Created:** [January 23, 2023, 11:39pm UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810 "2023-01-23T23:39:04Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheCodingCrusader22](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thecodingcrusader22/32/46084_2.png) [@TheCodingCrusader22](https://discourse.codecombat.com/u/TheCodingCrusader22)\
**Post date:** [January 23, 2023, 11:39pm UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/1 "2023-01-23T23:39:04Z")

</div>

soi am doing reindeer Tender but thir is a strang error  
my code:

```python
# 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:

 ![Screenshot 2023-01-23 173810](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/7/2/72021eb68db9757051b523dd24f1a1e8fc0ddd05.png)

---

<div class="post-metadata">

**Author:** ![Red-backspider](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/red-backspider/32/23212_2.png) [@Red-backspider](https://discourse.codecombat.com/u/Red-backspider)\
**Post date:** [January 23, 2023, 11:59pm UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/2 "2023-01-23T23:59:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TheCodingCrusader22](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thecodingcrusader22/32/46084_2.png) [@TheCodingCrusader22](https://discourse.codecombat.com/u/TheCodingCrusader22)\
**Post date:** [January 24, 2023, 12:32am UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/3 "2023-01-24T00:32:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Red-backspider](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/red-backspider/32/23212_2.png) [@Red-backspider](https://discourse.codecombat.com/u/Red-backspider)\
**Post date:** [January 24, 2023, 1:17am UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/4 "2023-01-24T01:17:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TheCodingCrusader22](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thecodingcrusader22/32/46084_2.png) [@TheCodingCrusader22](https://discourse.codecombat.com/u/TheCodingCrusader22)\
**Post date:** [January 24, 2023, 1:21am UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/5 "2023-01-24T01:21:01Z")

</div>

i removed it (20 chars)

---

<div class="post-metadata">

**Author:** ![Red-backspider](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/red-backspider/32/23212_2.png) [@Red-backspider](https://discourse.codecombat.com/u/Red-backspider)\
**Post date:** [January 24, 2023, 1:23am UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/6 "2023-01-24T01:23:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Red-backspider](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/red-backspider/32/23212_2.png) [@Red-backspider](https://discourse.codecombat.com/u/Red-backspider)\
**Post date:** [January 24, 2023, 1:27am UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/7 "2023-01-24T01:27:44Z")

</div>

im dumbfounded ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

---

<div class="post-metadata">

**Author:** ![Red-backspider](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/red-backspider/32/23212_2.png) [@Red-backspider](https://discourse.codecombat.com/u/Red-backspider)\
**Post date:** [January 24, 2023, 1:34am UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/8 "2023-01-24T01:34:58Z")

</div>

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()`

---

<div class="post-metadata">

**Author:** ![TheCodingCrusader22](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thecodingcrusader22/32/46084_2.png) [@TheCodingCrusader22](https://discourse.codecombat.com/u/TheCodingCrusader22)\
**Post date:** [January 24, 2023, 5:38pm UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/10 "2023-01-24T17:38:04Z")

</div>

my new code:

```python
# 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

---

<div class="post-metadata">

**Author:** ![Red-backspider](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/red-backspider/32/23212_2.png) [@Red-backspider](https://discourse.codecombat.com/u/Red-backspider)\
**Post date:** [January 24, 2023, 8:06pm UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/11 "2023-01-24T20:06:43Z")

</div>

try again, maybe some seeds are bad

---

<div class="post-metadata">

**Author:** ![JustALuke](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/justaluke/32/43608_2.png) [@JustALuke](https://discourse.codecombat.com/u/JustALuke)\
**Post date:** [January 24, 2023, 8:28pm UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/12 "2023-01-24T20:28:28Z")

</div>

🫠 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.

---

<div class="post-metadata">

**Author:** ![JustALuke](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/justaluke/32/43608_2.png) [@JustALuke](https://discourse.codecombat.com/u/JustALuke)\
**Post date:** [January 24, 2023, 8:31pm UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/13 "2023-01-24T20:31:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TheCodingCrusader22](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thecodingcrusader22/32/46084_2.png) [@TheCodingCrusader22](https://discourse.codecombat.com/u/TheCodingCrusader22)\
**Post date:** [January 24, 2023, 9:19pm UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/14 "2023-01-24T21:19:38Z")

</div>

my new code:

```python
# 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

---

<div class="post-metadata">

**Author:** ![TheCodingCrusader22](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thecodingcrusader22/32/46084_2.png) [@TheCodingCrusader22](https://discourse.codecombat.com/u/TheCodingCrusader22)\
**Post date:** [January 25, 2023, 12:07am UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/15 "2023-01-25T00:07:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [January 25, 2023, 12:08pm UTC](https://discourse.codecombat.com/t/solved-reindeer-tender-trouble/34810/16 "2023-01-25T12:08:10Z")

</div>

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