Close

Two consoles play chess in 31 bytes, and never connect

A project log for Braino! — a 40-game learning console on a CYD

Open-source ESP32 handheld with 40 learning games, from Maths to Chess over Bluetooth. No Accounts, No Telemetry. Flashes from a browser.

ankush-panditAnkush Pandit • a day ago•0 Comments

A BLE advertisement carries 31 bytes. Not 31 bytes of free space: 31 bytes total, counting every AD structure's own length and type byte. With the flags, the manufacturer block header and a name long enough to be recognisable, Braino's advertisement was already exactly 31 bytes before a chess move existed.

So a move could not be added. It had to displace something.

What went was the score. When two consoles are playing each other, neither cares what the other's best score in Memory is, so those four bytes became a session number, a move number, two square numbers and an ack. Thirty-two bits is enough, because a square is six bits and there are 64 of them.

Three things follow.

The game is a broadcast, not a connection. No pairing, no bonding, no GATT, no central and no peripheral. Both consoles advertise and both scan. Everyone in range hears every move and only the two playing act on them. Walk out of range and the game pauses rather than dropping.

Every received move is checked for legality in the receiver's own position before it is played, so a hostile advertiser can waste a scan window but cannot corrupt a board.

Ending a game rides the same field. A move whose source and destination are the same square is never legal, so it cannot be mistaken for a real one, and it costs nothing in a payload with nothing to spare.

Backgammon, Sea Battle and Ludo now use the same transport. None of them knows what the others' moves mean.

Discussions