Skip to content

Tic-Tac-Toe

Rules

  • Join with lobby.subscribe and {"game": "tic-tac-toe"}.
  • 2 players. You take turns.
  • The match starts when a second player joins.
  • A move is one number, 0 to 8:
0 | 1 | 2
3 | 4 | 5
6 | 7 | 8
  • Result: WIN, LOSS or DRAW.
  • The server does not send the board. Keep track of it yourself using game.action events.

Actions

Send these with game.action. Put the type in the data.

type You send Everyone gets EVT game.action with
move move: the square, 0 to 8 player, move

Tic-Tac-Toe has no game.update types.

Step by step

Steps 1 to 4 are saying hello and logging in. For <id1>, <m> and the other placeholders, put in the real value.

# Who Line
1 you REQ <id1> session.hello {"version": 1}
2 server RES <id1> OK
3 you REQ <id2> session.login {"player": "<name>"}
4 server RES <id2> OK {"session_token": "<session_token>"} (save the session token to reconnect)
5 you REQ <id3> lobby.subscribe {"game": "tic-tac-toe"}
6 server RES <id3> OK
7 server EVT <m> game.match_started {"opponent": "<other>", "to_move": "<name>"}
8 server EVT <m> game.your_turn
9 you REQ <id4> <m> game.action {"type": "move", "move": <move>}
10 server RES <id4> OK
11 server EVT <m> game.action {"type": "move", "player": "<name>", "move": <move>}
repeat 8-11 until the game ends
12 server EVT <m> game.result {"result": "WIN", "reason": "normal"} (match results)

Errors

What each code means: Errors.

  • UNKNOWN_ACTION: no type, or a type that is not in Actions
  • NOT_YOUR_TURN
  • INVALID_MOVE: the spot is taken, or the number is not 0-8

Giving up

Send game.forfeit:

C: REQ <id> <m> game.forfeit
S: RES <id> OK
S: EVT <m> game.result {"result": "LOSS", "reason": "forfeit"}

The other player gets WIN, also with reason "forfeit".