Hi guys, sorry I haven’t been around for a while. With the new lockdown now, schoolwork has got in the way a bit. But I’m back! I just need to know how to create a good visited array for treasured in ice and which search engine is best for CoCo. Help would be appreciated!
so you’re asking how to make an array…?
Oh sorry, I didn’t phrase that correctly. I am asking about how to loop through each coordinate I have been to and find out if I have been there or not and move somewhere else.
I don’t understand what you mean?
oh, I’m trying to summon @Eric_Tang
I’m in the mountain, that sounds like it’s in glacier.
Yeah it’s in the glacier. It’s ok though, just that I have been stuck on this level for a month. Sounds crazy
I’m not at this level yet Drangonlouis.
Sorry, I am only on the first level of Glacier.
Hmm I know that @Chaboi_3000 and @Deadpool198 have done have finished CoCo, maybe they can help. Note: because I was stuck on this level for quite a significant amount of time, I tried the “cheat” code but even the “cheat” code did not work! Here is my code:
distance = 16 move = Vector(distance, 0) direction = Vector.add(move, hero.pos) visited =  while True: if hero.isPathClear(hero.pos, direction): move = Vector.rotate(move, Math.PI / 2) direction = Vector.add(move, hero.pos) visited.append(direction) for visit in visited: if visited[-1] == visit: move = Vector.rotate(move, -Math.PI / 2) direction = Vector.add(move, hero.pos) hero.moveXY(direction.x, direction.y)
I don’t think I’ll be able to get past this level
Hello again. Sorry about not posting on the other topic.
I think the logic of your code is slightly wrong.
You first check if the path is clear, but when it is you rotate the vector.
I have a suggestion.
while not hero.isPathClear(hero.pos, direction):
This way you can rotate the
move vector until you reach a place you can move to. Then you redefine
direction = Vector.add(move, direction).
You’re rotating by the right amount (Math.PI/2 radians == 90 degrees), so that’s good.
After the while loop, you know that the current direction is a clear path, but you don’t know if you’ve visited it before so you loop through visited and check if the visit.x is the same as the direction.x and the visit.y is the same as the direction.y. You will probably need to round those numbers to 0 decimal places because sometimes the positions can have decimal points.
If the visit is the same as the direction, you can rotate the move vector and redefine direction.
Then after the for loop use an if to check if the path is clear to the direction (it may have changed in the for loop). If it is you move there, and if it isn’t it will go back to the first while loop and rotate it again. It will then find a new place that is different from the previous place and you can move there.
This may sound confusing, but try to write bits of code section by section and I will help you more.