Skip to content

Instantly share code, notes, and snippets.

@dforsyth
Last active December 11, 2015 01:59
Show Gist options
  • Select an option

  • Save dforsyth/4527794 to your computer and use it in GitHub Desktop.

Select an option

Save dforsyth/4527794 to your computer and use it in GitHub Desktop.
compile me
int north;
int east;
int south;
int west;
int dir;
int
survey()
{
north = ffi(@look, @north);
east = ffi(@look, @east);
south = ffi(@look, @south);
west = ffi(@look, @west);
}
int
clear()
{
north = -1;
east = -1;
south = -1;
west = -1;
}
int
act()
{
if (north == @cell_robot) {
dir = 0;
return ffi(@punch, @north);
}
if (east == @cell_robot) {
dir = 1;
return ffi(@punch, @east);
}
if (south == @cell_robot) {
dir = 2;
return ffi(@punch, @south);
}
if (west == @cell_robot) {
dir = 3;
return ffi(@punch, @west);
}
if (north == @cell_resource) {
return ffi(@pull, @north);
}
if (east == @cell_resource) {
return ffi(@pull, @east);
}
if (south == @cell_resource) {
return ffi(@pull, @south);
}
if (west == @cell_resource) {
return ffi(@pull, @west);
}
if (dir == 0) {
return ffi(@move, @north);
}
if (dir == 1) {
return ffi(@move, @east);
}
if (dir == 2) {
return ffi(@move, @south);
}
if (dir == 3) {
return ffi(@move, @west);
}
}
int
main()
{
dir = 0;
while (1) {
clear();
survey();
act();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment