Skip to content
English

Communication

Your program talks to the game through two devices that every robot has:

  • The emitter sends messages to the game. It does not need to be enabled.
  • The receiver gets messages from the game. Enable it like a sensor.

Each section below is a complete program for the starter robot. All the messages are listed in the Message Reference.

To score a letter victim or a cognitive target, the robot must:

  1. Stop for more than 1 second close to the token. Erebus ignores the report if the robot has moved in the last second.
  2. Send the position and type of the token: X and Z in centimetres, and the type as one letter.
Wall token Type
Letter victim Φ (harmed) H
Letter victim Ψ (stable) S
Letter victim Ω (unharmed) U
Cognitive target, sum 0 (Flammable Gas) F
Cognitive target, sum 1 (Poison) P
Cognitive target, sum 2 (Corrosive) C
Cognitive target, sum 3 (Organic Peroxide) O

The types are letters, even though victims show symbols since 2026. The GPS gives metres, so multiply by 100.

from controller import Robot
import struct
robot = Robot()
timeStep = int(robot.getBasicTimeStep())
emitter = robot.getDevice("emitter") # Always on the robot. It does not need to be enabled.
gps = robot.getDevice("gps")
gps.enable(timeStep)
leftWheel = robot.getDevice("left wheel motor")
rightWheel = robot.getDevice("right wheel motor")
leftWheel.setPosition(float("inf"))
rightWheel.setPosition(float("inf"))
def wait(seconds):
start = robot.getTime()
while robot.step(timeStep) != -1:
if robot.getTime() - start >= seconds:
break
def report(tokenType):
# 1. Stop for more than 1 second
leftWheel.setVelocity(0)
rightWheel.setVelocity(0)
wait(1.2)
# 2. Send the position in centimeters, and the type as one letter
x, _, z = gps.getValues()
message = struct.pack("i i c", int(x * 100), int(z * 100), tokenType.encode())
emitter.send(message)
robot.step(timeStep)
report("H") # Reports a harmed victim (Φ) where the robot is
print("Reported")

The robot must be on the same side of the wall as the token, and both the robot and the position you send must be close to it. The rules require at most half a tile, so aim for that. Erebus v26.1 checks a distance of 9 cm.

Run this program at the start of world1.wbt: there is no token there, so the history of the control window shows Misidentification of Victim -5. A wrong report, including a report of a fake, costs 5 points, and each token can only be scored once.

The history of the control window after a wrong report and a map submission

When the robot is stuck, a lack of progress moves it back to the last checkpoint and costs 5 points. It happens automatically after 20 seconds without moving, and your program can also call it by sending L. Each time, the game sends L to the robot, so that your program knows its position has changed.

from controller import Robot
import struct
robot = Robot()
timeStep = int(robot.getBasicTimeStep())
emitter = robot.getDevice("emitter")
receiver = robot.getDevice("receiver")
receiver.enable(timeStep) # The receiver must be enabled
askedAt = None
while robot.step(timeStep) != -1:
# Call a lack of progress once, after 2 seconds
if askedAt is None and robot.getTime() > 2:
emitter.send(struct.pack("c", b"L"))
askedAt = robot.getTime()
# Listen for messages from the game
while receiver.getQueueLength() > 0:
data = receiver.getBytes()
if len(data) == 1 and data == b"L":
print("Lack of progress! The robot is back at the last checkpoint.")
receiver.nextPacket()

The receiver can get different messages, so check the length of each one before reading it, as in the example.

Send G to get the score and the time left. The game replies with a 16-byte message: the letter G, the score, the game time left and the real time left, in seconds.

from controller import Robot
import struct
robot = Robot()
timeStep = int(robot.getBasicTimeStep())
emitter = robot.getDevice("emitter")
receiver = robot.getDevice("receiver")
receiver.enable(timeStep)
lastAsked = 0
while robot.step(timeStep) != -1:
# Ask for the game information once a second
if robot.getTime() - lastAsked > 1:
emitter.send(struct.pack("c", b"G"))
lastAsked = robot.getTime()
while receiver.getQueueLength() > 0:
data = receiver.getBytes()
if len(data) == 16: # The game information is 16 bytes long
_, score, timeLeft, realTimeLeft = struct.unpack("c f i i", data)
print("Score:", round(score, 2), "Time left:", timeLeft, "s", "Real time left:", realTimeLeft, "s")
receiver.nextPacket()

The game time runs faster in swamps, and the game ends when either time runs out. Use both to know when to head back to the start.

Send E to end the game. If the robot is on the starting tile and has identified at least one wall token, it gets the 10% exit bonus.

from controller import Robot
import struct
robot = Robot()
timeStep = int(robot.getBasicTimeStep())
emitter = robot.getDevice("emitter")
robot.step(timeStep)
print("Ending the game")
# Ends the game. Send it on the starting tile, after identifying a token, to get the exit bonus.
# The game stops your program right after this message.
emitter.send(struct.pack("c", b"E"))
robot.step(timeStep)

Next, learn to tell the tokens apart in Wall Tokens.