Skip to content
Cort edited this page Dec 27, 2020 · 1 revision

This simulates a radio that can be used to communicate between robots in the arena.

How to use (Blocks)

Sending Messages

Every message must specify a destination robot and a destination mailbox.

  • Destination robot: This can be "robot 0" to "robot 3", "team mates", or "all". Robots 0 and 1 are in one team, and robots 2 and 3 are in another team. The sender robot is never included in the destination (ie. you will not receive your own message when sending to "all").

  • Mailbox: This can be any string, and you can use this to segregate different types of messages. There are no limits to the number of mailboxes. The recipient must use the same mailbox name in order to see the message. There is no requirement for the mailbox to be created by the recipient beforehand.

  • Message content: Any types of data can be sent, including string, numbers, and lists.

Receiving Messages

To receive messages, the recipient robot must specify which mailbox to check. There are two blocks that can be used to read messages...

  • "read next message in mailbox": This returns a list containing the content of the message and the numeric id of the sender robot. The message is removed from the mailbox by this block.

  • "read content of next message in mailbox": This returns only the content of the message and remove it from the mailbox.

  • Attempting to read messages when there are none in the mailbox will return a null.

  • The number of available messages in the mailbox can be checked using the "number of messages in mailbox" block.

Emptying mailbox

Messages are automatically removed from the mailbox when read, but if you need to empty the mailbox immediately without reading, you can use the "empty mailbox" block.

How to use (Python)

Initializing

radio = Radio()

Creates a new radio object.

Sending messages

radio.send(dest, mailbox, value)

Sends a message.

  • dest: Robot ID (integer 0 to 3), a list of robot id (eg. [1,3]), or the special strings 'team' or 'all'. Robots 0 and 1 are in one team, and robots 2 and 3 are in another team. The sender robot is never included in the destination (ie. you will not receive your own message when sending to "all").

  • mailbox: This can be any string, and you can use this to segregate different types of messages. There are no limits to the number of mailboxes. The recipient must use the same mailbox name in order to see the message. There is no requirement for the mailbox to be created by the recipient beforehand.

  • value: This can be any Javascript compatible data. Numbers, strings, list, and dicts should work.

Receiving messages

radio.read(mailbox)

This returns a tuple containing the content of the message and the sender ID (integer) in that order (ie. (content, senderID)), and remove the message from the mailbox. Returns none if there are no messages available in the specified mailbox.

Checking available messages

radio.available(mailbox)

Returns an integer representing the number of unread messages in the mailbox.

Emptying mailbox

radio.empty(mailbox)

Messages are automatically removed from the mailbox when read, but if you need to empty the mailbox immediately without reading, you can use this.

Clone this wiki locally