# This program turns the routerbot into an explorer robot.
# It roams with speed SPEED until it "sees" an obstacle in 
# front of him in the distance closer the DISTANCE. Then it 
# looks for better direction to go (the one w/o obstacles)
# and proceeds that direction.
# If you plan to increase SPEED please increase DISTANCE too
# as distance calculation typically takes 1-2 seconds

DISTANCE=6
SPEED=70

look ahead
look forward
while [ true ]; do
sleep 1
stop
if [ `get_distance` -gt $DISTANCE ]; then
go forward $SPEED
else
stop
look right
if [ `get_distance` -gt $DISTANCE ]; then
turn right90
look forward
go forward $SPEED
else
look left
if [ `get_distance` -gt $DISTANCE ]; then
turn left90
look forward
go forward $SPEED
else
turn left180
look forward
go forward $SPEED
fi
fi
fi
done


