"setmark" makes a mark on the current tile, detectable by "look mark" and "touch mark".
#v0
define charge_treasure
touch treasure
if yes forward
if yes finish
repeat
end charge_treasure
define charge_mark
touch mark
if yes forward
if yes finish
repeat
end charge_mark
define reset_on_mark
# assume we're facing away from the
# conveyor belt to start.
left
look mark
if yes charge_mark
# "charge_mark" may have overwritten
# the condition register, but it'll
# always overwrite it with "yes"
if yes left
if yes finish
right
right
look mark
if yes charge_mark
if yes right
if yes finish
# seeing the mark in neither
# direction, we're either out
# of visual range or
# we're standing on it.
# This is either a non-problem if
# we're a lot faster than the belt,
# or will solve itself pretty soon if
# we're a lot slower than the belt.
# In any case, just turn around.
right
end reset_on_mark
define grab_goodies
# starting on the mark, facing the belt
forward
right
# we rely on the robot
# being able to outrun the conveyor belt
# and the conveyor belt always having
# a treasure somewhere upstream
do charge_treasure
right
forward
do reset_on_mark
repeat
end grab_goodies
forward
setmark
do grab_goodies
