Challenge description Let the challenge description guide you to create a solution
The map The robot can be situated in different maps (worlds). You can look around by dragging the map with the mouse or touch. You can change the scale by using the zoom buttons, use the mouse scroll wheel or pinch to zoom gesture.
Script editor A solution is a script (program) created in this text field. Scripts are written instructions (commands), normally executed from left to right, top to bottom. Use the remote control to see what instructions you can use, or see the documentation below.
Execute To run your script, click the play button, and see if it solves the described problem. If not, you'll probably get a hint.

The robot will not simply understand everything you write in de code editor. It can only perform the following commands.

Move Command Description
forward Go one step forward.
Use forward(number) to do more steps at once.
backward Go one step backward.
Use backward(number) to do more steps at once.
left Make a quarter turn to the left.
Use left(number) to do more steps at once.
right Make a quarter turn to the right.
Use right(number) to do more steps at once.
Grab Command Description
pickUp Get the beacon in front of the robot
putDown Put a beacon in front of the robot
eatUp Pick up and destroy the beacon in front
Paint Command Description
paintWhite Put the brush with white paint to the ground
paintBlack Put the brush with black paint to the ground
stopPainting Stop painting, hide the brush
See Left Front Right
leftIsClear frontIsClear rightIsClear
leftIsObstacle frontIsObstacle rightIsObstacle
leftIsBeacon frontIsBeacon rightIsBeacon
leftIsWhite frontIsWhite rightIsWhite
leftIsBlack frontIsBlack rightIsBlack

repeat(n){...instructions...}
Repeats the instructions between curly brackets exactly n times.

Example:

# a square of 2x2
repeat(4)
{
	forward(2)
	right
}
                  

repeat{...instructions...}
Repeats the instructions between the curly brackets forever.

Example:

# Keep going forward forever
# (but eventually will result in continuous bumping into a wall)
repeat
{
	forward(1)
}

repeatWhile(condition){...instructions...}
Repeats the instructions between curly brackets as long as the condition holds. This condition must be a perception/seeing instruction (for example frontIsClear)

Example:

# keep going forward, until you can't go any further
repeatWhile(frontIsClear)
{
	forward(1)
}

break
Allows you to jump out of the loop (e.g. a repeat section) so it stops performing the instructions between curly brackets. The robot will resume performing the instructions left after the closing curly bracket of the loop.

Example:

# keep going forward, until you can't go any further
repeat
{
	if(frontIsObstacle)
	{
		break
	}
	else
	{
		forward(1)
	}
}
                  

if(condition){...instructions...}
Will perform the the instructions between curly brackets, only if the condition holds. Else the robot immediatly steps to the instructions written after the closing curly bracket.The condition must be a perception/seeing instruction (for example: frontIsClear)

Example:

# if you see white paint on your left, make it black
if(leftIsWhite)
{
	left
	forward(1)
	paintBlack
	stopPainting
	backward(1)
	right
}
                  

if(condition){...instructions...}else{...instructions...}
Will perform the the instructions between the first pair of curly brackets, only if the condition holds. Then it will not perform the instructions of the else block (second pair of instructions). When the condition does not hold, the robot will only perform the instructions in between the second pair of curly brackets. After it performed one of the instruction blocks, it will read the instructions after the last curly bracket.The condition must be a perception/seeing instruction (for example: frontIsClear)

Example:

# if you see white paint on your left, make it black
# else drive a few steps forward
if(leftIsWhite)
{
	left
	forward(1)
	paintBlack
	stopPainting
	backward(1)
	right
}
else
{
	forward(3)
}
                  
if(condition1){...instructions...} else if(condition2) {...instructions...}
Is a shorter notation for:
if(condition1){...instructions...} else { if(condition2) {...instructions...}}.
The code block of else is only executed if the second condition holds. This constructions is handy when you wan to do different things in different situations, and you want to do only code block. In the next example the robot is doing a single step in the right direction by following the white line.

Example:

if(frontIsWhite)
{
    # only if front is painted white
    forward(1)
}
else if(rechtsIsWit)
{
    # only if front is painted white
    right
    forward
}
else if(leftIsWhite)
{
    # only if front is painted white
    left
    forward
}
else
{
    # only when all previous situations where NOT the case
    right(2)
    forward
} 

The conditions of if- and repeatWhile-structures are so-called logical expressions. Such an expression will result in the value true or false, which is then used to decide to step to the appropriate part of the code to resume execution.

A logical expression can be a perception instruction, e.g.: leftIsWhite. Basic instructions may also be composed with the boolean operators not, and, or.

Example:

if(leftIsWhite)
{
    left    
    forward(1)    
}

The condition can also be refined to indicate more precisely when the corresponding instructions should be executed, by using (a combination of) the following operators.

Operation Alternative
notation
Number of
arguments
Explanation
not ~ 1

Negates the value of the argument :

Truth table :
not true = false
not false = true

Example:
not frontIsClear

and & 2

Only true when both arguments are true.

Truth table:
true and true = true
true and false = false
false and true = false
false and false = false

Example:
frontIsClear and rightIsWhite

or | 2

True when at least one of the arguments is true.

Truth table:
true or true = true
true or false = true
false and true = true
false and false = false

Example:
frontIsClear or rightIsWhite

The values true and false can be used directly, just like a perception instruction.

The order in which the operators occur is important (just as with multiplying and adding numbers). The operation not binds strongest, followed by and, followed by or. Brackets can be used to adjust the execution order.

Examples:

		
repeatWhile(not frontIsClear and (leftIsWhite or rightIsWhite)){
    forward(1)
}

if(flipCoin and not rightIsWhite)
{
    right
    backward(1)
}

if(true and false){
    #this instruction will never be executed
    forward(1)
}              

Comparing numbers
Another type of logical expressions is number comparison. Then you can make decision based on a given value. For example, only go to the right if a given variable is less than 5.

Example:

forward
maybeToRight(8)
forward

procedure maybeToRight(n){
    if(n < 5){
        right
    }
}
            
This is the complete list of comparators.
Comparator Example: true Example: false Explanation
== 3 == 3 1 == 2 Check for equality
~= 1 ~= 2 3 == 3 Check for inequality
< 1 < 2 3 < 3 Compare values with "less than"
<= 3 <= 3 2 <= 1 Compare values with "less than or equals"
> 2 > 1 3 > 3 Compare values with "greater than"
>= 3 >= 3 1 >= 2 Compare values with "greater than or equals"

procedure name(par1, par2, ... , parN){...instructions...}
Defines a new procedure with the name you want. The procedure can have zero or more parameters, which you may also give useful names. Here they are called par1, par2, . . . , parN. These are the variables you can use in the instruction between curly brackets. The code in a procedure will not be performed automatically, you have to write a 'procedure call' every time you want to perform the instructions in the definition (See next instruction).
Tip: create a new procedure when when you you use a sequence of instructions more than once.

Example:

# define how to draw a rectangle
procedure rectangle(width, height)
{
	paintWhite
	repeat(2)
	{
		forward(height)
		right
		forward(width)
		right
	}
	stopPainting
}
                  

name(arg1, arg2, . . . , argN)
Is the call to the procedure with the corresponding name and the same amount parameters as you have arguments. The argument, here called arg1, arg2, . . . , argN, are the particular values that will be used in the procedure definition.

Example:

# these instructions will be performed
forward(1)
rectangle(3,2) # a call to the 'rectangle' procedure
forward(3)
rectangle(1,4) # another call with other arguments


# this is the definition of 'rectangle'
procedure rectangle(width, height)
{
	paintWhite
	repeat(2)
	{
		forward(height)
		right
		forward(width)
		right
	}
	stopPainting
}                  

return(arg)
To stop executing a procedure before it reaches the end, use return from within a procedure definition. The program continues executing the commands after the corresponding call.

By default, a procedure return the value zero. You can change this by returning an expression.

Example:

# this instruction will be performed
forward(double(3))

# double the given amount
procedure double(n)
{
    return(2 * n)
}                  

Recursion
Procedures can be defined recursively. That means that you use the procedure you are defining in the procedure definition itself, by calling it. It takes a while to comprehend, but turns out to be a powerfull tool.

Example:

# these instructions will be performed
toWall()
right
forward

# go forward until you reach a wall
procedure toWall()
{
      # notice that no loops are used
      if(frontIsObstacle)
      {
          # stop "toWall" procedure
          return
      }
      else{
          # do one step
          forward
          # and do a recursive call!
          toWall()
      }
            }                 

+,-,*,/
With these operations, you can add, subtract, multiply an divide numbers. Note that the numbers have to be integers (whole numbers).

Example:

# using some arithmetic in expressions
forward(2+3)
if(3*4 < 13){
    x = 3
    left(x-2)
}
backward(-(3+4)/2)
                  

x = ...
With variables you can remember values under a name you can choose yourself. The values of these variables are available later in the entire script. You can get these values, by using the name again. You can remember values of any expression (so: numbers, calculations, logical expressions, see commands, return values).

Example:

# store a number
x = 42

# store another number, based on x
y = x / 2

# store a logical expression
clear = leftIsClear & frontIsClear & rightIsClear

# store the actual number of steps taken
# until you bumped (returned by "forward")
actual = forward(100)

if(clear){
     right(2)
     forward(actual) # go back
}
left(y)