Tic-Tac-Toe Bot-to-Bot Game Protocol

Purpose

This document defines the communication protocol for two Grok Bots:

messenger1

messenger2

The two Bots will automatically play Tic-Tac-Toe against each other.

messenger1 is responsible for initiating each game.

A new game should begin every 2 minutes.

Both Bots share the same Grok Bot computer and use a shared folder to store game information and completed game results.

1. Players

There are two players:

messenger1

messenger2

Only these two Bots may participate in a game.

messenger1 is always responsible for starting a new game.

2. Game Start (STRICT ORDER)

Every 2 minutes, messenger1 starts a new game by sending a message to messenger2.

Step A — Symbol choice (must complete first):

messenger1 sends exactly:

Choose your symbol: circle or cross.

messenger2 must respond with exactly one of:

circle

or

cross

messenger2 must NOT ask who goes first until after it has sent its symbol reply.

The symbol not selected by messenger2 automatically belongs to messenger1.

Example:

messenger1 -> messenger2: Choose your symbol: circle or cross.
messenger2 -> messenger1: circle

The result is:

messenger2 = circle
messenger1 = cross

If messenger2 asks "Do you want to go first?" before sending circle or cross, messenger1 must reject that message and require the symbol reply first.

3. Determine Who Goes First (ONLY AFTER SYMBOL)

Only after messenger2 has answered with circle or cross, messenger2 asks messenger1 whether messenger1 wants to make the first move.

Example:

messenger2 -> messenger1: Do you want to go first?

messenger1 responds with:

yes

or:

no

If the answer is yes, messenger1 makes the first move.

If the answer is no, messenger2 makes the first move.

4. Board Positions

The Tic-Tac-Toe board contains nine positions.

The positions are numbered from 1 through 9:

1 | 2 | 3
---------
4 | 5 | 6
---------
7 | 8 | 9

Position meanings:

1 = top-left
2 = top-center
3 = top-right
4 = middle-left
5 = center
6 = middle-right
7 = bottom-left
8 = bottom-center
9 = bottom-right

Empty cells are shown as a blank space or a dot when displaying the board.

5. Move Format

Every move must use the following format:

<symbol> <position>

Examples:

circle 1

means:

Place a circle in the top-left position.

cross 5

means:

Place a cross in the center position.

circle 9

means:

Place a circle in the bottom-right position.

Bot-to-bot move messages should stay in that compact format.

6. Turn Rules and Availability Check (REQUIRED)

Players alternate turns.

BEFORE choosing any move, a Bot MUST:

1. List all empty positions (1-9 that are not occupied).
2. Choose ONLY from that empty list.
3. Never pick an occupied position.
4. Never pick a position outside 1-9.
5. Never use the wrong symbol.

If there are no empty positions left:

- Do not attempt another move.
- Determine whether the game is over (win or tie).
- End the game per sections 7-8 and 10-11.

After receiving a valid move, the receiving Bot must:

Update its understanding of the board.

Verify that the position was previously empty.

Check whether the move created a winning combination.

Check whether the board is full (no empty spots).

If the game has not ended, choose a legal empty position only.

Send its move to the other Bot.

A Bot must never:

Play in an occupied position.

Play twice in a row.

Change symbols during a game.

Modify a move that has already been accepted.

7. Winning Conditions

A player wins by occupying any of these combinations:

1, 2, 3
4, 5, 6
7, 8, 9
1, 4, 7
2, 5, 8
3, 6, 9
1, 5, 9
3, 5, 7

After every move, both Bots must determine whether one of these combinations exists.

8. Game Results

A game may end with exactly one of the following results:

messenger1 win

messenger2 win

tie

A tie occurs when all nine positions are occupied and neither Bot has a winning combination.

Once the game has ended, no additional moves may be made.

9. Shared Folder

Both Bots must use the same shared folder:

/workspace/tictactoe/

Create the directory if it does not already exist.

Completed game results must be stored inside this directory.

10. Game Result File

When a game finishes, messenger1 is responsible for saving the final result.

Create one text file for every completed game.

Use a unique file name such as:

game-2026-09-03-110200.txt

Recommended contents include Game ID, players, symbols, first player, moves, final board drawing, and Result.

The Result field must contain exactly one of:

messenger1 win
messenger2 win
tie

11. Game Completion and Silence After End

After a win or tie is detected:

messenger1 saves the result file and confirms it exists.

End the current game immediately.

HARD STOP — both Bots:

Once either Bot knows the game is over (win or tie, or result file written), that Bot must NOT send any further messages for that game.

No more moves.

No late move attempts.

No “game already ended” replies.

No acknowledgements about the finished game to the other Bot.

Silence until messenger1 starts a brand-new game at the next scheduled interval.

At the next scheduled interval, messenger1 starts a completely new game.

12. Game Isolation

Every game is independent.

Moves from previous games must never be reused.

At the beginning of each new game:

board = empty
winner = none
moves = []

A unique Game ID must be assigned to each game.

13. Communication Responsibilities

The normal communication sequence is:

messenger1: Choose your symbol: circle or cross.
messenger2: circle   (REQUIRED before step below)
messenger2: Do you want to go first?
messenger1: yes
messenger1: cross 5
messenger2: circle 1
... continue until finished ...
messenger1 writes result file to /workspace/tictactoe/game-<game-id>.txt

14. Error Handling

If a Bot receives an invalid move, it must reject it and ask the sender to choose another position.

Examples of invalid moves:

Position is outside 1-9.

Position is already occupied.

Wrong symbol is used.

A player attempts two consecutive moves.

The game has already ended — if YOU already know it ended, do not send anything (not even a rejection). If you somehow receive a move before you knew it ended, do not reply; stay silent and leave the board unchanged.

Asking who goes first before answering circle/cross.

An invalid move must not modify the board.

15. Board Display (USER-VISIBLE STATUS) — BOTH BOTS

So the user can always see what is going on, BOTH messenger1 AND messenger2 must show a board drawing to the user after each of their own state changes:

- symbols are chosen (messenger2 after picking; messenger1 after recording)
- first player is decided
- every accepted move you just made or just accepted
- every rejected invalid move during an active game (board unchanged)
- game end (final board) — then stop messaging the other Bot

Use this layout (O = circle, X = cross, blank = empty):

```
Game <game-id>
 O |   | X
---------
   | O |
---------
 X |   | O
Last: circle 5
Empty: 2, 4, 6, 8
Status: in progress | messenger1 win | messenger2 win | tie
```

Also keep /workspace/tictactoe/current-board.txt updated with the same drawing so either Bot can read the latest visible state.

16. Important Rules

Both Bots must follow these rules for every game:

Follow this protocol exactly.

Communicate with the other Bot rather than simulating the other Bot's responses.

Never choose a move on behalf of the other Bot.

Maintain the same board state throughout a game.

Use only positions 1-9.

Use only circle and cross.

Before every move, verify the chosen position is empty.

If no empty spots remain, stop moving and resolve win/tie.

Detect wins and ties correctly.

Save every completed game's result.

Never overwrite an older game result.

Start each new game with an empty board.

Both messenger1 and messenger2 always show the board status drawing for the user after their state changes.

After game over, both Bots stay silent toward each other until a new game starts.
