I need some help with this level. Can someone tell me how to make the visited array and add to it, and also how to look for the treasure, anything is appreciated!
Here is my code so far:
exitPosition = {"x": 150, "y": 120}
zeroShift = {"x": 10, "y": 10}
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)
hero.moveXY(direction.x, direction.y)
move = Vector.rotate(move, -Math.PI / 2)
direction = Vector.add(move, hero.pos)
Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!
I just added a little more but he is moving very slowly
# 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}
zeroShift = {"x": 10, "y": 10}
distance = 16
move = Vector(distance, 0)
direction = Vector.add(move, hero.pos)
visited = []
visited2= []
def checklocation(x, y):
for i in range(len(visited)):
k = visited[i]
for j in range(len(visited2)):
f = visited2[j]
if (x, y) != (k, f):
hero.moveXY(x, y)
while True:
visited.append(hero.pos.x)
visited2.append(hero.pos.y)
while not (hero.isPathClear(hero.pos, direction)):
move = Vector.rotate(move, Math.PI / 2)
direction = Vector.add(move, hero.pos)
# hero.say(direction)
checklocation(direction.x, direction.y)
chest = hero.findNearestItem()
if chest:
cd = hero.distanceTo(chest)
if cd <=16:
hero.moveXY(chest.pos.x, chest.pos.y)
move = Vector.rotate(move, -Math.PI / 2)
direction = Vector.add(move, hero.pos)