Communicate with others
In this guide, we will learn how to communicate with other players using Quick Chat and emojis.
You can:
- Send Quick Chat messages with
Controller.send_quickchat - Send emojis with
Controller.send_emoji - React to received messages in your message handler via
DisplayChatMessageUpdateandEmojiUpdate
Sending Quick Chat
Quick Chat messages are predefined by category + key (for example greet.hello). Some messages also require a target player ID (for example attack.attack targeting a player).
The full list of valid categories/keys is documented in DisplayChatMessageUpdate.
# Say hello to a specific player.
await controller.send_quickchat("greet", "hello", some_player_id)
# Ask someone to attack a target player (requires target).
await controller.send_quickchat("attack", "attack", some_player_id, target_player_id)// Say hello to a specific player.
controller.sendQuickChat("greet", "hello", somePlayerId, null);
// Ask someone to attack a target player (requires target).
controller.sendQuickChat("attack", "attack", somePlayerId, targetPlayerId);Sending emojis
You can send an emoji either to one player or to all players. Only allowed emojis will work (see EmojiMessage).
# Send an emoji to one player.
await controller.send_emoji("🤝", some_player_id)
# Broadcast an emoji to everyone.
await controller.send_emoji("🔥", "AllPlayers")// Send an emoji to one player.
controller.sendEmoji("🤝", somePlayerId);
// Broadcast an emoji to everyone.
controller.sendEmoji("🔥", "AllPlayers");Reacting to incoming messages
Message handling is a great place to react to diplomacy signals.
if isinstance(update, DisplayChatMessageUpdate):
if update.equals("help.alliance") and update.playerID is not None:
sender_id = controller.small_id_to_player_id(update.playerID)
if sender_id is not None:
await controller.request_alliance(sender_id)
elif isinstance(update, EmojiUpdate):
recipient = update.emoji.recipientID
is_for_me = recipient == "AllPlayers" or controller.small_id_to_player_id(recipient) == state.me.id
if is_for_me and update.emoji.message == "🤝":
await controller.send_emoji("👍", update.emoji.senderID)if (updateObj instanceof GameState.DisplayChatMessageUpdate) {
GameState.DisplayChatMessageUpdate update = (GameState.DisplayChatMessageUpdate) updateObj;
if (update.equals("help.alliance") && update.playerID != null) {
PlayerID senderId = controller.smallIdToPlayerId(update.playerID);
if (senderId != null) {
controller.requestAlliance(senderId);
}
}
} else if (updateObj instanceof GameState.EmojiUpdate) {
GameState.EmojiUpdate update = (GameState.EmojiUpdate) updateObj;
boolean isForMe = false;
if (update.emoji.isAllPlayers()) {
isForMe = true;
} else {
PlayerID recipientId = controller.smallIdToPlayerId(new PlayerSmallID(update.emoji.getPlayerSmallID()));
isForMe = recipientId != null && recipientId.value.equals(state.me.id.value);
}
if (isForMe && "🤝".equals(update.emoji.message)) {
controller.sendEmoji("👍", update.emoji.senderID);
}
}A few notes on communication
There are no pre-defined semantics for Quick Chat messages or emojis. Of course, Attack [target] has a strong meaning attached to it, but ultimately, the real meaning of the message depends on what your bot uses it for and how other bots will interpret it.
Feel free to discuss with other teams of some form of "chat protocol" to attach more specific meanings to certain messages and emojis, and to make your alliances more effective.
You can also base your communication on bot usernames if you need to use different communication protocols with different bots.
Make sure to use communication wisely: spamming messages every loop may get you kicked from the tournament game, and even if it does not, it will likely annoy other players and make them less willing to ally with you.
Communication alone will not win games, but it can make your alliances more reliable and your opponents less coordinated. It can also be a fun way to interact with other players and add some personality to your bot.
