Let me preface this by saying I only just started learning JavaScript this month, and I have no prior experience with any other coding language.
Here is a part of the code I’ve written:
while (true) {
var E = parseInt(readline());//
var go;
function getPos(); // updates TX & TY
if (LX > TX && LY == TY)
{
go = E;
TX++;
}
}
print(go);
Obviously this is only a part of the code. But I’m getting an error that the program didn’t provide an input. I feel like I’m missing something really obvious…?
Thor’s moving…
Thor position = (35,17). Light position = (36,17). Energy = 1
Standard Output Stream:
SE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< should do E, why doesn’t it?
37/37
Game information:
Failure: Thor wandered off the path and died (invalid position).
Thor position = (36,18). Light position = (36,17). Energy = 1
/---------------------------------------------------------------------------
if logic(edited to not show full code)
if (TX < LX && TY == LY)
{
Console.WriteLine(“E”);
}
else if (TX < LX && TY < LY)
{
Console.WriteLine(“E”);
Console.WriteLine(“SE”);
}
Ok, I just wrote some code with a switch statement in C++ that beat all 4 Test cases, I submitted it and it gives me a 0% and the example cases on the results page look completely different than what I worked with. Does anyone know what went wrong?
switch (TX) {
case 5: cout << "LEFT" << endl; break;
case 6 ....
}
If that’s so, this is hardcoded, because you need to use the global position of thor to choose where to move, not just choose a path depending on the X/Y origin.
Yep, that’s the kind of code I’m using. I think I understand now, I need to have code that lets Thor find his way to the goal no matter where he is. Correct me if I’m wrong.
Thanks! Sorry if all of this is obvious, I’m still trying to get the hang of this site.
Hi, I think the example has broken narrative, the first two coordinates seem to be wrong.
“Thor starts on (3, 6), light on (3, 8).” -> … ->
“Thor moves South. New position = (3, 6). Thor has won”
You need to update TX and TY by yourself. They won’t have automagically the next position as they’re given in input only once at start, not every turn.
Just wanted to say. I had a lot of trouble with this and I thought it would be so easy. The issue ended up being that I was no updating Thor’s position in my game loop. In the test window it showed Thor’s updated position so I thought that was also happening in the code but it was not.
So don’t forget to update Thor’s current position in your code. TX++. TY ++ etc etc.