Created
September 29, 2016 11:33
-
-
Save byronmejia/f90fdf61c5a22926304bba4cc78ea0f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
typedef struct Thors { | |
int x; | |
int y; | |
} Thor; | |
int move(int x, int y, Thor *thor); | |
int move(int x, int y, Thor *thor ){ | |
if(x == 0 && y == 0) return -1; | |
if(y > 0) goto NORTH; | |
else if(y < 0) goto SOUTH; | |
else goto NEITHER; | |
NORTH: | |
thor->y--; | |
if(x < 0) { | |
printf("NE\n"); | |
thor->x++; | |
} | |
else if(x > 0){ | |
printf("NW\n"); | |
thor->x--; | |
} | |
else printf("N\n"); | |
return 0; | |
SOUTH: | |
thor->y++; | |
if(x < 0) { | |
printf("SE\n"); | |
thor->x++; | |
} | |
else if(x >0){ | |
printf("SW\n"); | |
thor->x--; | |
} | |
else printf("S\n"); | |
return 0; | |
NEITHER: | |
if(x < 0) { | |
thor->x--; | |
printf("E\n"); | |
} | |
else if(x > 0){ | |
thor->x++; | |
printf("W\n"); | |
} | |
else return -1; | |
} | |
/** | |
* Auto-generated code below aims at helping you parse | |
* the standard input according to the problem statement. | |
* --- | |
* Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders. | |
**/ | |
int main() | |
{ | |
float tempY; | |
int lightX; // the X position of the light of power | |
int lightY; // the Y position of the light of power | |
int initialTX; // Thor's starting X position | |
int initialTY; // Thor's starting Y position | |
scanf("%d%d%d%d", &lightX, &lightY, &initialTX, &initialTY); | |
Thor thor; | |
thor.x = initialTX; | |
thor.y = initialTY; | |
// game loop | |
while (1) { | |
int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line. | |
scanf("%d", &remainingTurns); | |
// ---------- Start Hacking Here -------------- | |
move(thor.x - lightX, thor.y - lightY, &thor); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment