Last active
December 11, 2015 01:59
-
-
Save dforsyth/4527794 to your computer and use it in GitHub Desktop.
compile me
This file contains hidden or 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
| 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