Power Of Thor - Episode 1 - Puzzle discussion

Why and how to update it?

The server give you the initial position of Thor (before the game loop). During the game, the server doesnā€™t provide the current thor position so you have to keep track of your movement to reach the light.

NORTH means going TOP, so ThorX will decrease and so one. Take a look at the statement below the viewer for more info.

For round 3 and 4, i have only 15 and 19 moves. Itā€™s not sufficient. Why i have not additionnal mouvement?

Hi guys,Iā€™m having some troubles. This is my code -> http://pastebin.com/yZs0Hc0h

It behaves strangely, is like Thor takes input only the first time then it keep moving in the same direction for every turn.

Is a mistake on my part in the code? :\

lol forget it guys, thanks to SwagColoredKitteh in the chat made me realize I wasnā€™t updating thor initial position, so it kept repeating the first move xD
For some reason I thought it was auto-updating xD

There is something I donā€™t understand and before I continue I am new to coding so please donā€™t burn me. Anyways I am trying to code for this game but what I donā€™t understand is in the pseudo code they create both directionX and directionY as empty stringsā€¦why? I seriously do not understand this. I really donā€™t understand when and why to do this. in this situation.

Iā€™m sort of stumped, I am acutely aware of my ignorance in this but this works right up until the last step. My code is simple if somewhat inelegent I think but obviously thereā€™s a floor, Iā€™m using
if (thorY < lightY) { ydir = "S"; thorY ++ ; }
and the like to determine what directions I need to go and then

` if (ydir == ā€œSā€ && xdir == ā€œEā€)
{
Console.WriteLine(ā€œSEā€);
}

to tell it what to write. It works up until the last square on the first, third and fourth tests and Thor just stops. C# obviously but any ideas? `

Well, the unique element in the second test (the one you pass) is that it is vertical motion only, no horizontal. If you stop right near the end, then I assume that you must have some off-by-one error in your calculation of Thorā€™s horizontal position.

I recommend that you start putting some Console.Error.WriteLine() debug messages into your code to help you figure out what itā€™s trying to do.

  • danBhentschel

you probably need to return E as a string variable, not as a char (they are two very different things)

Hello guys!
Iā€™m having trouble in the ā€œeasy angleā€ and ā€œoptimal angleā€ cases.

The code segment is as follows:

`
if(lightY==initialTY){
if(lightX<initialTX){
dirX=ā€œWā€;
dirY="";
}
if(lightX>initialTX){
dirX=ā€œEā€;
dirY="";
}
}
if(lightX==initialTX){
if(lightY>initialTY){
dirY=ā€œSā€ ;
dirX="";
}
if(lightY<initialTY){
dirY=ā€œNā€;
dirX="";
}
}
ā€¦

System.out.println("dirY+dirX);


Thor wanders off through the border in both cases.
Thanks for your help.

P.S. How do I display less than sign in the code ?? :confused:

By styling your code as preformatted text (</>):

if (lightY==initialTY) {
    if (lightX<initialTX) {
        dirX="W";
        dirY="";
    }
    if (lightX>initialTX) {
        dirX="E";
        dirY="";
    }
}
if (lightX==initialTX){
    if (lightY>initialTY) {
        dirY="S";
        dirX="";
    }
    if (lightY<initialTY) {
        dirY="N";
        dirX="";
    }
}
System.out.println(dirY+dirX);

A lot nicer isnā€™t it? By the way, in english, initialValue means Ā« the starting value Ā». To be honest, calling it dynamicValue wonā€™t solve your problem (thatā€™s just a clue).

1 Like

I think this game has a bug. I copy/paste the solution of this game from the hint section. In spite of that, the second and third test cases failed.
Do you have any Idea?

hey @areftd, this is one of the most classic game on the platform and almost 100 thousand CodinGamers have resolved it, so I can tell you there is no bug :wink:

A hint is a tip/clue to help you solve the puzzle, not a solution.

thank you for the replying :slight_smile:

I am very sorry for my last feedbackā€¦ you are totally correctā€¦ finally I found the problemā€¦
simply I had re-assigned the initial_x, initial_y, light_x and light_y to another variables inside the ā€œwhile loopā€ which led to failure in the last test cases.

stupid things happens!

itā€™s fine, donā€™t worry :slight_smile:

usually there is no bug, and by spending a bit more time, we can find our mistake. But well, forum is also there to find answers

keep coding :wink:

On the Java version when ever you go SW SE the Thorā€™s y coordinate always stays his starting value. I put in a few debug statements to try and prove this. I think there is a bug in the calling code where it is not putting the incorrect parameter for y. Can anyone else try it.

Debug out put
Game information:
Thorā€™s ready to go.
Thor position = (31,4). Light position = (0,17). Energy = 44
01
15
Standard Error Stream:
mythor(31,4)
mythorXY(-1,1)
Standard Output Stream:
SW
Game information:
Thorā€™s movingā€¦
Thor position = (30,5). Light position = (0,17). Energy = 43
02
15
Standard Error Stream:
mythor(30,4)
mythorXY(-1,1)
Standard Output Stream:
SW
Game information:
Thorā€™s movingā€¦
Thor position = (29,6). Light position = (0,17). Energy = 42
03
15
Standard Error Stream:
mythor(29,4)
mythorXY(-1,1)
Standard Output Stream:
SW
Game information:
Thorā€™s movingā€¦
Thor position = (28,7). Light position = (0,17). Energy = 41

ā€¦there is a bug in the calling code where it is not putting the (in)correct parameter for y.

What is this calling code you are talking about? This puzzle only gives you Thorā€™s position at the begining and itā€™s up to you to calculate its actual position each turn. So, if your mythor variable value is wrong, how could it be the game engine fault? Stated in different words, how could it be responsible in any way of the following inequality?

mythorn+1 ā‰  mythorn + mythorXYn
where
mythor0 = (initialTX, initialTY)

I am running into the same issue. What I think is happening is the Y coordinate of his last position is being input incorrectly.
if you debug with the your own output statement you will see that they Y never changes though Thor moves SW. Are you also running this in JAVA? I hate to come up with a work around if input is actually wrong.

The code that is calling is always passing the same value for Y =4. It never changes while the X is subtracted. You can see it in the mythor(x,y) output. Yes I could code around it but that is not the point. The input value for Y is wrong.

Iā€™m baffledā€¦ The game does not provide Thorā€™s updated position. The mythor variable and how it is updated from turn to turn is your code. This is you who has written the code which changes mythor value. So, if mythor value is wrong, how could be that it is not you who made some mistake?