# [SOLVED] Treasured in Ice Javascript CS6

Is it me or is there a bug in “Treasures in Ice”? I’ve no idea if it’s just me unable to crack the egg or if there’s some bug that needs to be fixed. Ima post the source code for you to see… and by the way, I’m in the subscribed version of Coco just for info…

1 Like

What issue did you find at this level?

Andrei

2 Likes

I think the problem is being unable to find the position of the treasure and then being able to navigate towards it. There aren’t any twilight glasses that can help me find it in the first place. So I’m a bit lost…

Secondly, the process to solve the level before (which is supposed to teach us to navigate in the ice maze) is extremely advanced and I didn’t get it at all. (I found it on github doing research on difficulties encountered solving the level ). Adding a treasure hunt on top for me scrambles my thinking even more.

Finally, with every submission, the position of the treasure could change. I think that we’re missing an element to be able to solve it. What it is though? no clue @Anna

1 Like

It is possible. After every step try to find a nearest item and if you find one, then collect it and then go the exit.

Andrei

2 Likes

I can share the site with the navigation code for the previous level. Just to show what it’s like and see if there’s an alternative… @AnSeDra

1 Like

So use the code from the previous level to get around and look for the treasure every time after you move and when you see it, collect it and then use the moving algorithm to move to the exit.

Andrei

1 Like

Ok. I’ll try to do that. I’ll let you know if I encounter any problems.

1 Like

Here is my code for the level. Unsure what to do…

``````// 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.

var exitPosition = {x: 150, y: 120};
var distance = 16;
var zeroShift = {x: 10, y: 10};
var move = Vector(distance, 0);

while (true) {
var treasure = hero.findNearestItem();
while (!hero.isPathClear(hero.pos, direction)) {
move = Vector.rotate(move, Math.PI / 2);
}
pathToFollow.push(hero.pos);
if (treasure) {
hero.moveXY(treasure.pos.x, treasure.pos.y);
for (var i = pathToFollow.length; i > 0; i--) {
var point = pathToFollow[i];
hero.moveXY(point.x, point.y);
}
}
hero.moveXY(direction.x, direction.y);
move = Vector.rotate(move, Math.PI / -2);

}

``````

Andrei

What is going wrong in this? can you send me a screenshot?

@AnSeDra Is there any way to check if the hero has gone in a circle andfind a way to break the circle in Javascript? I don’t usually use Javascript so I don’t know.

I am not sure. Maybe someone else knows.

Andrei

Okay. I’ve no idea myself. Thank you anyway

2 Likes

Also, does anyone know what the “zeroShift” variable (in the code post 8) is supposed to do? I have a feeling that it might just make a difference in my approach to solving this puzzle. Thank you @Anna

Does anybody really have no idea as to what to do? @AnSeDra @Anna @Deadpool198

Can you show me your code?

2 Likes

Okay.

``````// 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.

var exitPosition = {x: 150, y: 120};
var distance = 16;
var zeroShift = {x: 10, y: 10};
var move = Vector(distance, 0);

while (true) {
var item = hero.findNearestItem();
while (!hero.isPathClear(hero.pos, direction)) {
move = Vector.rotate(move, -Math.PI / 2);
}

hero.moveXY(direction.x, direction.y);
move = Vector.rotate(move, Math.PI / 2);