# Treasured In Ice (python)

**URL:** <https://discourse.codecombat.com/t/treasured-in-ice-python/22467>\
**Category:** Level Help\
**Created:** [June 23, 2020, 1:18am UTC](https://discourse.codecombat.com/t/treasured-in-ice-python/22467 "2020-06-23T01:18:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenma](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@kenma](https://discourse.codecombat.com/u/kenma)\
**Post date:** [June 23, 2020, 1:18am UTC](https://discourse.codecombat.com/t/treasured-in-ice-python/22467/1 "2020-06-23T01:18:15Z")

</div>

my hero does not move at all in this level, and for yDif it says that ‘pos’ is undefined. here is my code:

```python
exitPosition = {"x": 150, "y": 120}
hero.wait(.1)
chest = hero.findItems()[0]
walls = [[0] * 4 for i in range(100)]
steps = []

def direction(n):
    x = 0
    y = 0
    if n == 0:
        y += 16
    elif n == 1:
        x += 16
    elif n == 2:
        y -= 16
    else:
        x -= 16
    return {"x": hero.pos.x + x, "y": hero.pos.y + y}

while True:
    jMod = 0
    doNext = True
    lastStep = (steps[-1] + 2) % 4
    yDif = hero.pos.y - chest.pos.y # <---------- this line has an error, 'pos' not defined
    xDif = hero.pos.x - chest.pos.x
    if hero.distanceTo(chest) < 5:
        break
    if yDif > 1:
        if xDif > 1:
            jMod = 2
        else:
            jMod = 1
    else:
        if xDif > 1:
            jMod = 3
    # hero.say(jMod)
    for j in range(4):
        i = (j + jMod) % 4
        checkPoint = direction(i)
        if hero.isPathClear(hero.pos, checkPoint) and walls[len(steps)][i] == 0 and i != lastStep:
            hero.moveXY(checkPoint.x, checkPoint.y)
            steps.append(i)
            doNext = False
            break
    if doNext:
        checkPoint = direction(lastStep)
        walls[len(steps) - 1][steps[-1]] = 1
        steps.pop()
        hero.moveXY(checkPoint.x, checkPoint.y)

while hero.distanceTo(exitPosition) > 10:
    checkPoint = direction((steps[-1] + 2) % 4)
    steps.pop()
    hero.moveXY(checkPoint.x, checkPoint.y)

hero.moveXY(exitPosition.x, exitPosition.y)

```

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [June 23, 2020, 3:20am UTC](https://discourse.codecombat.com/t/treasured-in-ice-python/22467/3 "2020-06-23T03:20:01Z")

</div>

As @EpicCoder9999 said, try to make your own solution if you want us to help you solve it, not copy it from github, is that clear?

---

<div class="post-metadata">

**Author:** ![kenma](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@kenma](https://discourse.codecombat.com/u/kenma)\
**Post date:** [June 23, 2020, 7:08pm UTC](https://discourse.codecombat.com/t/treasured-in-ice-python/22467/4 "2020-06-23T19:08:16Z")

</div>

Ok, thanks for your suggestions!

---

<div class="post-metadata">

**Author:** ![kenma](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@kenma](https://discourse.codecombat.com/u/kenma)\
**Post date:** [June 23, 2020, 11:41pm UTC](https://discourse.codecombat.com/t/treasured-in-ice-python/22467/5 "2020-06-23T23:41:03Z")

</div>

here is the new code, my hero can run and stuff but it doesn’t actually go to the chest

```python
inSearch = True

width = 19
height = 15

def coorConvert(i, dist):
    return i * 8 + 10

wall = "X"
unknown = "?"
empty = "."

maze = []
# left border
for i in range(height):
    maze.append([wall])
for j in range(width - 1):
    maze[0].append(wall)
for i in range(height - 1):
    if i % 2:
        for j in range(width - 1):
            maze[i].append(unknown)
    else:
        for j in range(width - 1):
            if j % 2:
                maze[i].append(wall)
            else:
                maze[i].append(unknown)

for j in range(width - 1):
    maze[height-1].append(wall)
for i in range(height):
    maze.append([wall])

hero.row = 13
hero.col = 17
exitRow = 13
exitCol = 17

item = hero.findNearest(hero.findItems())
distance = 16
move = Vector(distance, 0)
direction = Vector.add(move, hero.pos)
while True:
    while not (hero.isPathClear(hero.pos, direction)):
        move = Vector.rotate(move, Math.PI / 2)
        direction = Vector.add(move, hero.pos)
    hero.moveXY(direction.x, direction.y)
    move = Vector.rotate(move, -Math.PI / 2)
    direction = Vector.add(move, hero.pos)

```
