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 ??
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).
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
A hint is a tip/clue to help you solve the puzzle, not a solution.
thank you for the replying
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
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
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?