Power Of Thor - Episode 1 - Puzzle discussion

your code is incomplete you nedd to implement NE, NW, SE,SW

There is definitely a bug in your code. My solution does what you describes (“E” and increment initial_tx by 1) and it works fine.

No, the site is not bugged. There are multiple issues with your code, one of which is that it does not update Thor’s position after he moves, so your code is always comparing Thor’s initial position and the target position.

By the way, please use the </> button on the formatting toolbar to format your code properly in this forum.

I need help. Something wrong about the coordinates. The game information telling me that the initial_ty value is increasing everytime thor is going south, but when I print initial_ty, it actually decreasing :confused: I’m working with python 3. Here’s my code :

light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()]

def goNorth():
    global initial_ty
    initial_ty += 1
    
    print("thor y:",initial_ty, file=sys.stderr, flush=True)
    print("light y:",light_y, file=sys.stderr, flush=True)

def goWest():
    global initial_tx
    initial_tx -= 1
    
    print("thor x:",initial_tx, file=sys.stderr, flush=True)
    print("light x:",light_x, file=sys.stderr, flush=True)

def goSouth():
    global initial_ty
    initial_ty -= 1
    print("thor y:",initial_ty, file=sys.stderr, flush=True)
    print("light y:",light_y, file=sys.stderr, flush=True)

def goEast():
    global initial_tx
    initial_tx += 1
    
    print("thor x:",initial_tx, file=sys.stderr, flush=True)
    print("light x:",light_x, file=sys.stderr, flush=True)

def goNorthEast():
    goNorth()
    goEast()
def goSouthEast():
    goSouth()
    goEast()
def goSouthWest():
    goSouth()
    goWest()
def goNorthWest():
    goNorth()
    goWest()


# game loop
while True:
    remaining_turns = int(input())  # The remaining amount of turns Thor can move. Do not remove this line.
    if remaining_turns > 0 :
        if initial_ty > light_y and initial_tx < light_x:
            goNorthEast()
            print("NE")
        elif initial_ty < light_y and initial_tx < light_x:
            goSouthEast()
            print("SE")
        elif initial_ty < light_y and initial_tx > light_x:
            goSouthWest()
            print("SW")
        elif initial_ty > light_y and initial_tx > light_x:
            goNorthWest()
            print("NW")
        elif initial_tx < light_x:
            goEast()
            print("E")
        elif initial_tx > light_x:
            goWest() 
            print("W")
        elif initial_ty > light_y:
            goNorth()
            print("N")
        elif initial_ty < light_y:
            goSouth()
            print("S")
        
    # Write an action using print
    # To debug: print("Debug messages...", file=sys.stderr, flush=True)

    remaining_turns -= 1
    # A single line providing the move to be made: N NE E SE S SW W or NW

You need to amend your code. As stated in the statement,

Note that the coordinates (X and Y) start at the top left!

When Thor goes north, his y-coordinate decreases, but your code increases it, and when he goes south, his y-coordinate increases, but your code decreases it.

Same here, also on Java. Maybe got any idea what is wrong? Did you solve it?

That player hasn’t been seen on the forum for over a year. Maybe you can describe what your current code does, and what error messages are shown in the console, so that others can help you?

That would be nice. My problem is that on easy angle test Thor reached light Y and still moves further.

Game information:

Failure: Thor wandered off the path and died (invalid position). Thor position = (17,18). Light position = (0,17). Energy = 31

For now I think that I should change while condition. Am I on the right track? :sweat_smile:

Maybe you haven’t updated the variables correctly, or written some wrong conditions? The best way to check is to add some code to print what the variables are at the end of each while loop. You may use the syntax provided in the initial default code:
// To debug: System.err.println("Debug messages...");

For example, before the line of code where you print the direction, you may add this line:
System.err.println(LX + " " + LY + " " + TX + " " + TY);
This will help you investigate where things may have gone wrong.

Thank you. I’ll try that.

Gonna assume this is dead but I’ll try anyway.

First I can bearly code so no judgement this is messy as hell.
Second I’m just using a bunch of if else if else if else if el… and he starts great always going the right way but will go out of bounds. all my statements are (thor_x > light_x && thor_y > light_y) kind of statements but I cant get him to stop his path once x or y are equal.

If you can barely code, start learning the basics (logic and code) outside of CodinGame and come back later to retry.

4 Likes

Yeah. I’m not brand new to it but realized I still have a while before I’ll be back here. Not exactly as noob friendly as it lead me to believe. Thanks.

Hey everyone! I’m starting a code club at my campus and last week I introduced five students to The Power of Thor, Episode 1. After about an hour of trying at it some had gotten pretty close. I filmed this solution, and plan to keep making videos to help get more beginners learning on this platform. Please share it with anyone you know that’s trying to learn to code, and if you had any difficulty with this puzzle this should help you get through it. Feedback welcome! :slight_smile:

What is the difference between
cout >> Y >> X
and
cout >> X >> Y
???

You read the first value as X then the second as Y (cout X Y) … or Y then X (cout Y X).

This game has a bug up & down not working

Probably your code contains the bug which causes up and down not to work. You may PM your code to me to have a look.

The puzzle is about about conditionals and I have to move Thor using console.log()…what is going on.??

Basically the games on Codingame tell you where the character is and where he needs to go. You then have to print out a move in the format the game wants. If you read through the sample code, it tells you what it wants but then prints a wrong move. You have to use logic taking in the inputs every loop to print out where to go.

Thor wants moves in “L” for left, “R” for right, “U” for up, and “D” for down. It allows you to move diagonally in one move by using, for ex: “RD” for right and down. You would build your move string with an if/then conditional to calculate how to move and build your move string accordingly.

if(thor.x < target.x && thor.y < target.y ) { move = “RD”; }
else if (thor.x < target.x && thor.y == target.y ) { move = “R”; }
else if (thor.x < target.x && thor.y > target.y ) { move = “RU”; }
//…and so on

then send it to the console:

console.log(move);