How do my bots share information with their teammates?
The radio
A radio is a part (3 kg) that goes on the spare mount, so in the standard loadout it's channel 3. Each teammate needs one too.
from bot import Scanner, Radio, cpu, wait
scanner = Scanner(1)
radio = Radio(3)
SEEN = 1 # the team's code for "I see something"
while True:
x, y, z = radio.read()
if scanner.ping(0) and cpu.tick % 10 == 0:
radio.send(SEEN, x, y, scanner.bearing(0))
m = radio.receive()
if len(m) == 4 and m[0] == SEEN:
log("teammate at {}, {} sees something at {}", m[1], m[2], m[3])
wait()
radio.heardis true while a teammate's radio is heard. Thenmx, my, mz = radio.teammate()gives that teammate's position, sent automatically every tick.radio.send(a, b, c, d)sends one to four numbers at your nextwait(). Every live teammate gets them the next tick; enemies don't, and neither do you. A second send in the same tick replaces the first.m = radio.receive()gives the message shown now, as a list (empty when none came).radio.messageis how many numbers it holds, andradio.waitinghow many more messages are queued. It shows one message per tick and queues up to 8 more; past that the oldest are lost.
What the numbers mean is up to your team. A good habit: make the first number say what kind of message it is.
The team notepad
The notepad needs no part: import it with from bot import notepad. There are no strings, so characters are numbers, their codes: ord("A") is 65.
from bot import notepad, wait
while True:
if notepad.char(0) == ord("B"):
log("plan B")
wait()
notepad.length,notepad.char(i)andnotepad.find(c, i)read it.notepad.write(i, c)puts one character;notepad.put(i, x)writes a number as text and gives the index just after it.notepad.number(i)reads a number back.- A bot can make up to 32 character edits a tick. Edits go out at
wait(), and every bot on the team, this one too, reads the new text from the next tick. - It belongs to the team, not the match: each match starts with the text the last one left. Good for plans, such as a letter that picks today's tactic.
- Write on a line of its own, never inside a
log(...).
Which to use?
Use the radio for things that change fast: positions and targets. Use the notepad for slower shared state, and anything to keep for the next match. It costs cycles (about 25 a character read, up to 360 to write a number), so keep it short.