2. Your First RUR-PLE Program: Basic Movements
The RUR-PLE robot is controlled by several basic commands. You can combine these commands to create complex actions.
2.1. Basic RUR Robot Commands
move(): Moves the robot one step forward in its current direction.turn_left(): Rotates the robot 90 degrees to the left.turn_right(): Can be implemented by callingturn_left()three times. (RUR-PLE may not have a built-inturn_right(); implement it yourself or use threeturn_left()calls.)take(): Picks up one beeper from the square the robot is on.put(): Places one beeper on the square the robot is on.front_is_clear(): ReturnsTrueif there is no wall in front of the robot,Falseotherwise.on_beeper(): ReturnsTrueif the robot is on a beeper,Falseotherwise.
2.2. Simple Example: Moving a Beeper
The following code is an example that moves the robot, picks up a beeper, turns right, moves again, and then places the beeper.
# beeper_mover.py
# Function to turn the RUR robot right
def turn_right():
turn_left()
turn_left()
turn_left()
move() # Move forward one step
take() # Pick up a beeper
turn_right() # Turn right
move() # Move forward one step
put() # Put down a beeper
Before running this code, you should configure a world with a beeper in front of the robot using RUR-PLE's 'World Editor'. Save the world configuration and then run your code.