Skip to content

Instantly share code, notes, and snippets.

@sanxiyn
Created June 5, 2012 02:41
Show Gist options
  • Save sanxiyn/2872199 to your computer and use it in GitHub Desktop.
Save sanxiyn/2872199 to your computer and use it in GitHub Desktop.
Robot
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