Help: Treasured In Ice

my hero only moves in a certain way and it does not reach the chest, im not sure why
also can someone explain what Vector does

``````# Find the treasure inside the maze.
# When you get the treasure, move to the exit.
# The exit is marked by the red cross. The level ends when you step on the mark.
# Some doors are blocked, some open when you are near them.

exitPosition = {"x": 150, "y": 120}
distanceBetweenRooms = 16
zeroShift = {"x": 10, "y": 10}

# Escape from the maze!
# Some doors are blocked, some open when you are near them.
distance = 16
move = Vector(distance, 0)
while True:
while not (hero.isPathClear(hero.pos, direction)):
move = Vector.rotate(move, Math.PI / 2)
# hero.say(direction)
hero.moveXY(direction.x, direction.y)
move = Vector.rotate(move, -Math.PI / 2)

inSearch = True

width = 19
height = 15

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)
while True:
while True:
while not (hero.isPathClear(hero.pos, direction)):
move = Vector.rotate(move, Math.PI / 2)
# hero.say(direction)
hero.moveXY(direction.x, direction.y)
move = Vector.rotate(move, -Math.PI / 2)

``````

``````# I stole this
# https://codecombat.com/play/level/treasured-in-ice
# Find the treasure inside the maze.
# When you get the treasure, move to the exit.
# The exit is marked by the red cross. The level ends when you step on the mark.
# Some doors are blocked, some open when you are near them.

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

``````

it says cannot read proptery “2” of undefined

@ineedhelpwithcoding and @cxctia
i have solution both of you

[Code removed by a moderator: Please don’t post successful solutions as it is counterproductive to the learning process]