Skip to content

Instantly share code, notes, and snippets.

@lessandro
Last active December 11, 2015 11:19
Show Gist options
  • Save lessandro/4593063 to your computer and use it in GitHub Desktop.
Save lessandro/4593063 to your computer and use it in GitHub Desktop.
new bot
// GridC to GridLang compiler
// https://github.com/lessandro/gridc
int xs[30];
int ys[30];
int ds[30];
int num;
int starve;
void eat(dir) {
if (ffi(@LOOK, dir) == @CELL_ROBOT) ffi(@PUNCH, dir);
if (ffi(@LOOK, dir) == @CELL_RESOURCE)
if (ffi(@PULL, dir))
starve = 0;
}
int seek(dx, dy, dir) {
if (ffi(@SCAN, dx, dy) == @CELL_RESOURCE) {
ffi(@MOVE, dir);
return 1;
}
return 0;
}
void main() {
i = 0;
d = 2;
while (d < 4) {
n = 0;
while (n < d) {
m = d - n;
xs[i] = n; ys[i] = 0 - m; ds[i] = @NORTH; i = i + 1;
xs[i] = m; ys[i] = n; ds[i] = @EAST; i = i + 1;
xs[i] = 0 - n; ys[i] = m; ds[i] = @SOUTH; i = i + 1;
xs[i] = 0 - m; ys[i] = 0 - n; ds[i] = @WEST; i = i + 1;
n = n + 1;
}
d = d + 1;
}
num = i;
i = 0;
eat(@NORTH);
eat(@SOUTH);
eat(@WEST);
eat(@EAST);
stuck = 0;
starve = 0;
for (i = 0; i < num; i = i + 1) {
if (ffi(@SCAN, xs[i], ys[i], ds[i]) == @CELL_RESOURCE) {
eat(@NORTH);
eat(@SOUTH);
eat(@WEST);
eat(@EAST);
if (ffi(@LOOK, ds[i]) == @CELL_ROCK) {
stuck = stuck + 1;
if (stuck == 5)
ffi(@SELFDESTRUCT, 1);
} else {
if (ffi(@MOVE, ds[i]))
i = -1;
starve = starve + 1;
if (starve == 5) {
ffi(@SELFDESTRUCT, 1);
starve = 0;
}
}
}
}
ffi(@SELFDESTRUCT, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment