Treasured in Ice

Hi. I need help with this level, I start it but now don’t know how to do, this is my code:
(Hola. Necesito ayuda en este nivel, lo empecé pero ahora no sé que hacer, este es mi código):ç

inSearch = True
width = 19
height = 15
def coorConvert(i, dist):
    return i * 8 + 10
wall = "X"
unknown = "?"
empty = "."
maze = []
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
distance = 16
move = Vector(distance, 0)
direction = Vector.add(move, hero.pos)
distanceBetweenRooms = 16
startRoom = {"x": 150, "y": 120}
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.say(direction)
    item = hero.findNearest(hero.findItems())
    items = hero.findItems()
    for item in items:
        hero.move(item.pos)
    hero.moveXY(direction.x, direction.y)
    move = Vector.rotate(move, -Math.PI / 2)
    direction = Vector.add(move, hero.pos)
hero.moveXY(150, 120)

Thank you

1 Like

Why did you get rid of all the comments? (your old post: Help! : Treasured in Ice)


I took your code and added comments:

inSearch = True   # variable not used

# This whole section is not used in your algorithm yet.
# When you do have a use for it, you can uncomment it back
# by selecting all lines with comments
# and then pressing control + '?'
#
# width = 19
# height = 15
# def coorConvert(i, dist):
#     return i * 8 + 10
# wall = "X"
# unknown = "?"
# empty = "."
# maze = []
# 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


distance = 16
move = Vector(distance, 0)
direction = Vector.add(move, hero.pos)

distanceBetweenRooms = 16                # variable not used
startRoom = {"x": 150, "y": 120}         # variable not used

distance = 16                            # redundant code
move = Vector(distance, 0)               # redundant code
direction = Vector.add(move, hero.pos)   # redundant code


while True:     # can't exit the loop
    
    # replace this comment with something that explains what this while loop does
    while not (hero.isPathClear(hero.pos, direction)):
        move = Vector.rotate(move, Math.PI / 2)
        direction = Vector.add(move, hero.pos)
        #hero.say(direction)
    
    # add a useful comment here about the following code
    item = hero.findNearest(hero.findItems()) # variable not used before reassignment
    items = hero.findItems()  # as far as I know, there is only 1 item
    for item in items:
        hero.move(item.pos)
    
    # why is this section split apart from the while loop above?
    # they both deal with hero movement through the maze
    hero.moveXY(direction.x, direction.y)
    move = Vector.rotate(move, -Math.PI / 2)
    direction = Vector.add(move, hero.pos)

hero.moveXY(150, 120)  # this code never executes

Things to consider:

3 Likes