Treasured in ice help

Hello, can anybody help me?

Can anybody help me? Here is my code.

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

what does the error say?

2 Likes

can someone please help me this is my code

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

anyone? @CODEBOY2 @jaden_the_best @AnSeDra @JEFF @Chaboi_3000 @Shurutsue @ducky @Luke10 @123hi123

it says here that cannot read property 2 of undefined

help this is my code:
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)

ursa just keeps moving in a rectagler shape

It’s not very accurate to say it’s your code, considering it was written by someone who isn’t you, and you just copied it from github.
However, I shall try to help you with this (slightly infuriating) level. I would recommend first reviewing all vector levels that you’ve completed so far. This may sound a little boring, but, as you probably know, Vectors are hard, but you can get better at using them by relearning what you first learnt and practicing it in levels like dueling grounds (try writing something to avoid the enemy, based off the level “skating-away”).
Then try your very best to write some code (try using while loops and hero.isPathClear(vector1, vector2)) and post it here and I will do my upmost to help you with it.
This level is very hard, and I can understand why you have struggled with it. I had to wait 2 years to be good enough to solve it myself, but it’s definitely possible to do it faster than that :grin:.
Danny

1 Like

I will give you a strategy:
Make arrays called goodPaths and badPaths.
Make a function called convertCoordinate(x, y) to make the colum and row of a coordinate in the maze
Define chest_of_gems as hero.findItems()[0]
and coords_of_gems as convertCoordinate(chest_of_gems.pos.x, chest_of_gems.pos.y)
The hard work, you can figure it out.


i need help with my code

Hey @Shurutsue, welcome the forum

Hi goutham but this person is not aactive.

Um Mr.@Eric_Tang , since your are on here, I would just like some help on treasured in Ice, I don’t even now how to get started, so could you please help me??

regards,
Goutham123

I was not online actually I was doing a test. And I have not completed this level either.

Sorry @Eric_Tang for disturbing you in the middle of a test

can someone help me now?

# Define the exit position
exitX = 150
exitY = 120

# Step size for moving in the maze
step = 16

# Movement directions
directions = ["left", "up", "right", "down"]
directionOffsets = {
    "left": {"x": -step, "y": 0},
    "right": {"x": step, "y": 0},
    "up": {"x": 0, "y": step},
    "down": {"x": 0, "y": -step}
}

# Visited locations (as a set for faster lookups)
visited = []

# Function to compute the next position
def nextPosition(direction, pos):
    return {"x": pos.x + directionOffsets[direction]["x"], "y": pos.y + directionOffsets[direction]["y"]}

# Function to move smoothly with Winged Boots
def smartMove(target):
    while not hero.isAt(target["x"], target["y"]): 
        hero.move(target)  # Moves gradually with Winged Boots

# Start direction
currentDirection = "up"

while True:
    # Look for treasure
    treasure = hero.findNearestItem()
    
    if treasure:
        # Move to treasure, then exit
        smartMove({"x": treasure.pos.x, "y": treasure.pos.y})
        smartMove({"x": exitX, "y": exitY})
        break  # Stop looping once the hero reaches the exit

    moved = False

    # Try moving in all four directions
    for _ in range(4):  
        tryPoint = nextPosition(currentDirection, hero.pos)
        posKey = (tryPoint["x"], tryPoint["y"])  # Tuple key for visited tracking

        # Move if path is clear and not visited
        if hero.isPathClear(hero.pos, tryPoint) and posKey not in visited:
            smartMove(tryPoint)  # Use Winged Boots movement
            visited.append(posKey)  # Mark as visited
            moved = True
            break  # Stop checking once a move is made

        # Rotate to the next direction
        currentDirection = directions[(directions.index(currentDirection) + 1) % 4]

    # If stuck, backtrack to the last visited point
    if not moved and visited:
        lastX, lastY = visited.pop()
        smartMove({"x": lastX, "y": lastY})  # Use smooth movement