Your code is the robot's brain. The robot starts on its dock. Dust lifts on the first pass. Dark sticky spots need a second pass.
Move these take time
forward(50) | Drive 50 cm. Stops early if it hits something. Gives back the cm it moved. |
forward() | Drive until it hits something. |
back(10) | Reverse 10 cm. |
right(90) left(90) | Turn on the spot, in degrees. |
turn_to(0) | Face a compass heading. 0 north, 90 east, 180 south, 270 west. |
wait(2) | Sit still for 2 seconds. |
Sense these are instant
bumped() | True if the last drive hit something. |
front_dist() left_dist() right_dist() | Distance to the nearest thing, in cm. Sees up to 400. |
dirt() | Grime left under the robot. 0 means spotless. More means a sticky spot: leave and come back over it. |
x() y() | Position in cm from the north-west corner. y grows south. |
heading() | Compass heading in degrees. |
home_x() home_y() at_home() | Where the dock is, and whether you are on it. |
cleaned() battery() time() | Percent cleaned, percent battery left, seconds used. |
Language
x = 5 # a variable
if x > 3 and not bumped():
forward(x * 10)
elif x == 3:
left()
else:
right()
while battery() > 10: # loop while true
forward()
repeat 4: # loop 4 times
forward(30)
right(90)
for i in range(10): # i = 0, 1 ... 9
log(i)
def square(size): # your own command
repeat 4:
forward(size)
right(90)
square(60)
spots = [3, 4] # a list
spots.append(5)
last = spots.pop()
grid = [0] * 100 # 100 zeros
grid[7] = 1
Also: break continue return global in, and the helpers random(a, b) log(...) abs min max int round floor sqrt sin cos atan2 len str. Angles are in degrees.
Score
Up to 800 points for floor cleaned. Up to 150 for battery left, but only if your program ends by itself with over 80% cleaned. 50 for parking on the dock. 900 earns an S.