Created
June 5, 2012 02:41
-
-
Save sanxiyn/2872199 to your computer and use it in GitHub Desktop.
Robot
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
void move_robot(int direction); | |
int pick(void); | |
void put(void); | |
#define SIZE 1000 | |
enum { LEFT, RIGHT, UP, DOWN }; | |
enum { NOTHING, TREASURE, BOMB }; | |
static int current_x; | |
static int current_y; | |
void move_to(int x, int y) { | |
while (current_x < x) { move_robot(RIGHT); current_x++; } | |
while (current_x > x) { move_robot(LEFT); current_x--; } | |
while (current_y > y) { move_robot(DOWN); current_y++; } | |
while (current_y < y) { move_robot(UP); current_y--; } | |
} | |
void move_to_home(void) { | |
move_to(0, 0); | |
} | |
void move_to_trash(void) { | |
move_to(SIZE - 1, SIZE - 1); | |
} | |
void run_test(void) { | |
int x, y, object; | |
for (y = 0; y < SIZE; y++) { | |
for (x = 0; x < SIZE; x++) { | |
move_to(x, y); | |
object = pick(); | |
switch (object) { | |
case TREASURE: | |
move_to_home(); | |
put(); | |
break; | |
case BOMB: | |
move_to_trash(); | |
put(); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment