콘텐츠로 이동
한국어

통신

프로그램은 모든 로봇에 있는 두 장치를 통해 게임과 통신해요.

  • **이미터(emitter)**는 게임에 메시지를 보내요. 활성화할 필요가 없어요.
  • **리시버(receiver)**는 게임에서 메시지를 받아요. 센서처럼 활성화하세요.

아래 각 섹션은 스타터 로봇용의 완성된 프로그램이에요. 모든 메시지는 메시지 레퍼런스에 나와 있어요.

문자 피해자(Letter victim)나 인지 표적(Cognitive target)으로 점수를 얻으려면 로봇은 다음을 해야 해요.

  1. 토큰 가까이에서 1초 넘게 정지해요. 로봇이 직전 1초 안에 움직였다면 Erebus는 보고를 무시해요.
  2. 토큰의 위치와 종류를 보내요. X와 Z는 센티미터 단위로, 종류는 문자 하나로 보내요.
벽 토큰 종류
문자 피해자 Φ (부상) H
문자 피해자 Ψ (안정) S
문자 피해자 Ω (무사) U
인지 표적, 합 0 (Flammable Gas, 인화성 가스) F
인지 표적, 합 1 (Poison, 독극물) P
인지 표적, 합 2 (Corrosive, 부식성 물질) C
인지 표적, 합 3 (Organic Peroxide, 유기 과산화물) O

2026년부터 피해자는 기호로 표시되지만, 종류는 문자예요. GPS는 미터 단위이므로 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")

로봇은 토큰과 같은 쪽 벽에 있어야 하고, 로봇과 보내는 위치 모두 토큰 가까이에 있어야 해요. 규칙에서는 최대 반 타일까지로 정하고 있으니 그 안을 목표로 하세요. Erebus v26.1은 9 cm 거리로 확인해요.

이 프로그램을 world1.wbt의 시작 지점에서 실행해 보세요. 그곳에는 토큰이 없으므로 제어 창의 기록에 Misidentification of Victim -5가 표시돼요. 가짜를 보고하는 것을 포함해 잘못 보고하면 5점이 깎이고, 각 토큰은 한 번만 점수를 얻을 수 있어요.

잘못된 보고와 지도 제출 후의 제어 창 기록

로봇이 갇혔을 때 진행 불능(Lack of Progress, LoP)이 발생하면 로봇은 마지막 체크포인트(Checkpoint)로 돌아가고 5점을 잃어요. 20초 동안 움직이지 않으면 자동으로 발생하고, 프로그램이 L을 보내서 선언할 수도 있어요. 그때마다 게임이 로봇에 L을 보내므로, 프로그램은 위치가 바뀌었다는 것을 알 수 있어요.

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()

리시버는 여러 종류의 메시지를 받을 수 있으므로, 예제처럼 읽기 전에 각 메시지의 길이를 확인하세요.

G를 보내면 점수와 남은 시간을 받을 수 있어요. 게임은 16바이트 메시지로 응답해요. 문자 G, 점수, 남은 게임 시간, 남은 실제 시간(초 단위)이에요.

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()

늪에서는 게임 시간이 더 빨리 흐르고, 둘 중 어느 시간이든 다 되면 게임이 끝나요. 두 시간을 모두 사용해서 언제 출발점으로 돌아갈지 판단하세요.

E를 보내면 게임이 끝나요. 로봇이 시작 타일에 있고 벽 토큰을 하나 이상 식별했다면 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)

다음으로 벽 토큰에서 토큰을 구별하는 법을 배워 보세요.