Can someone help me plz?
I tried to make this puzzle in C but everytime I Thor runs off the map and dies in test 3/4.
I have no idea what I did wrong and I can't show the full code so I will try to explain what I did.
The variables are TX, TY, LX, LY and the scanf is already put in place.
I start with
Then I just put all the if rules to run in the 8 destinations.
I will just show the first one and then the rest are just like this one.
So if (TX < LX)
if (TY < LY)
TX = TX++;
TY = TY++;
Then I go on with TY > LY and TY == LY and then comes the entire TX > LX and after the TX == LX
And it just ends with
It seems that when Thor is on (18,17) and the light is on (0,17) Thor just runs of the map and dies.
Standard Output Stream:
Failure: Thor wandered off the path and died (invalid position).
Thor position = (17,18). Light position = (0,17). Energy = 31
Why does he does this? At (18,17) Thor has 18>0 and 17 = 17 so TX > LX and TY == LY so he should run W but he keeps going SW.
I also read throughout this thread that it has to do with updating Thors position but didn't I do that with the TX = TX++ or TX = TX-- etc ...?
And do you have to make a difference between Thors initial position and Thors current position so having variables
TX, TY, LX, LY, TIX (thor initial X), TIY (thor initial Y)?
I am confused =(