PROTOCOL.md

Tue, 25 Aug 2026 18:59:18 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 25 Aug 2026 18:59:18 +0200
changeset 194
619f07c95894
parent 192
e57e2874fb2a
permissions
-rw-r--r--

rename Row to Rank

+ fix increase type safety where we overlooked it before

relates to #956

182
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 # terminal-chess Network Protocol
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 The network protocol for terminal-chess is designed in an interoperable manner,
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 allowing for playing chess with other clients that implement the same protocol.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 This document describes the protocol in detail, including the message formats
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 and the expected behavior of clients and the server.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8
192
e57e2874fb2a fix how agreeing on a draw works
Mike Becker <universe@uap-core.de>
parents: 191
diff changeset
9 The current protocol version is 25.
182
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 ## Message Format
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 The terminal-chess network protocol has two different message types:
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 * a code consisting of a single byte
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * a message composed of a single byte indicating the type plus a payload
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 An example implementation covering both types is the following struct:
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 ```C
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 struct message {
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 unsigned char code;
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 unsigned char message[]; // flexible array member
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 }
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 ```
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 A table with all message codes can be found [below](#message-code-table).
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 The datatypes used in the message payloads are as follows:
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 * BYTE — a single byte
183
39aa77b7188b fix missing byte-order conversion in ntoh_move() and change protocol byte order to little-endian
Mike Becker <universe@uap-core.de>
parents: 182
diff changeset
32 * WORD — two bytes integer (little-endian)
39aa77b7188b fix missing byte-order conversion in ntoh_move() and change protocol byte order to little-endian
Mike Becker <universe@uap-core.de>
parents: 182
diff changeset
33 * DWORD — four bytes integer (little-endian)
182
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 * MOVE — a data structure describing a move, consisting of
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 * a DWORD for the elapsed move time in seconds
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 * a DWORD for additional elapsed move time in microseconds
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 * a BYTE describing the moved piece (see below)
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 * a BYTE index for the file the piece was moved from
194
619f07c95894 rename Row to Rank
Mike Becker <universe@uap-core.de>
parents: 192
diff changeset
39 * a BYTE index for the rank the piece was moved from
182
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 * a BYTE index for the file the piece was moved to
194
619f07c95894 rename Row to Rank
Mike Becker <universe@uap-core.de>
parents: 192
diff changeset
41 * a BYTE index for the rank the piece was moved to
186
8230904458a7 fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
42 * a BYTE set to 1 if this is a capturing move and to zero if it is not
8230904458a7 fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
43 * a BYTE set to 1 if this move gives check, 2 if it gives checkmate, and
8230904458a7 fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
44 zero otherwise
182
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45 * a BYTE describing the selected piece for promotion (otherwise zero)
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46
183
39aa77b7188b fix missing byte-order conversion in ntoh_move() and change protocol byte order to little-endian
Mike Becker <universe@uap-core.de>
parents: 182
diff changeset
47 Note carefully that the byte order used by this protocol is little-endian while
39aa77b7188b fix missing byte-order conversion in ntoh_move() and change protocol byte order to little-endian
Mike Becker <universe@uap-core.de>
parents: 182
diff changeset
48 the standard network byte order would be big-endian. But since the vast majority
39aa77b7188b fix missing byte-order conversion in ntoh_move() and change protocol byte order to little-endian
Mike Becker <universe@uap-core.de>
parents: 182
diff changeset
49 of processors use little-endian nowadays, this protocol uses little-endian, too.
39aa77b7188b fix missing byte-order conversion in ntoh_move() and change protocol byte order to little-endian
Mike Becker <universe@uap-core.de>
parents: 182
diff changeset
50
182
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 The following table shows the possible values for the BYTEs describing a piece.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 | Piece | Value (Hex) |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 |--------------|-------------|
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 | White Pawn | 0x11 |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 | White Rook | 0x12 |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 | White Knight | 0x13 |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 | White Bishop | 0x14 |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 | White Queen | 0x15 |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 | White King | 0x16 |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 | Black Pawn | 0x21 |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 | Black Rook | 0x22 |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 | Black Knight | 0x23 |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 | Black Bishop | 0x24 |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 | Black Queen | 0x25 |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 | Black King | 0x26 |
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 ## Handshake
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 Immediately after a connection between a server and a client is established,
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 the server SHALL send one single byte denoting the protocol version to the
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 client.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 The client SHALL then immediately answer with their protocol version.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 After both parties have sent their version to the other party, they SHALL both
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 compare their own version with the received version.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 When the versions do not match, both parties SHALL terminate the connection.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 The users SHOULD be informed about the protocol mismatch.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 ## Game Setup
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 After a successful handshake, the server SHALL send the client information about
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 the game they want to play. The server can set up a completely new game or
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 continue an unfinished game.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 ### Starting a New Game
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86
191
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
87 When the server wants to start a new game, they SHALL send a `GAMEINFO`
182
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 message. The payload of this message is as follows:
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 * one BYTE denoting the color the server wants to play
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 (16 or 0x10 = white, 32 or 0x20 = black)
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 * one BYTE indicating if the game is played with time control (1 = yes, 0 = no)
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 * one WORD for the initial clock time in seconds
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 * one WORD for the number of seconds that are added per move
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 * one WORD for the delay in seconds for each move
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 When the game is played without time control, the last three WORDs MAY be
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 left uninitialized, but they SHALL be sent anyway.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 ### Continuing a Game
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100
191
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
101 When the server wants to continue a game, they SHALL send a `PGNDATA`
182
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 message. The payload of this message is as follows:
191
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
103 * the same two BYTEs and three WORDs as in `GAMEINFO`, followed by
184
93c81539b702 fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents: 183
diff changeset
104 * one WORD for the number `n` of moves that will follow
93c81539b702 fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents: 183
diff changeset
105 * the `n` MOVEs that have been played already
93c81539b702 fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents: 183
diff changeset
106
93c81539b702 fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents: 183
diff changeset
107 The server SHOULD NOT send a game that cannot be continued because it already
93c81539b702 fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents: 183
diff changeset
108 has reached a checkmate, stalemate, or forced draw position.
182
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 ### Clock Setup
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 For clock synchronization, the following rules SHALL be applied:
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 * the clock of each player starts after their first move
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 * the _increment_ is added _after_ a move, except…
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 * … when the initial clock is zero, then the clock starts with the increment
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 * when the used time for a move is less than the delay, the move costs no time
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 * the delay is always subtracted from the actual move time
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119
184
93c81539b702 fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents: 183
diff changeset
120 ## Playing the Game
93c81539b702 fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents: 183
diff changeset
121
186
8230904458a7 fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
122 The game is played by exchanging moves.
8230904458a7 fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
123 We call the player supposed to make the next move the _active_ player.
8230904458a7 fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
124 The other player we call the _waiting_ player.
8230904458a7 fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
125
8230904458a7 fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
126 ### Make a Move
8230904458a7 fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
127
191
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
128 If the active player wants to make a move, they SHALL send a `MOVE` message
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
129 with one MOVE payload to the waiting player.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
130 The active player SHALL then wait for an `ACCEPT_MOVE` or `DECLINE_MOVE`
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
131 message.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
132
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
133 When the waiting player receives a `MOVE` message, they SHOULD validate the
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
134 move. When validation fails, they SHALL send a `DECLINE_MOVE` message with one
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
135 byte indicating the reason why the move is declined.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
136 Otherwise, they SHALL send an `ACCEPT_MOVE` message.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
137
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
138 When the move is accepted, both players SHALL swap the active / waiting role.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
139
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
140 The reasons for declining a move are listed in the following table:
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
141
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
142 | Reason | Value | Description |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
143 |-----------------------|-------|---------------------------------------------|
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
144 | INVALID_MOVE_SYNTAX | 1 | E.g., indices out of bounds |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
145 | PIECE_NOT_FOUND | 2 | The piece is not at the specified position. |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
146 | NEED_PROMOTION | 4 | Target piece for promotion is missing. |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
147 | PIECE_PINNED | 5 | Piece cannot move because it is pinned. |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
148 | KING_IN_CHECK | 6 | The move would leave the king in check. |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
149 | KING_MOVES_INTO_CHECK | 7 | The king would be moved into check. |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
150 | MISSING_CHECK | 8 | The check-flag was not set. |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
151 | MISSING_CHECKMATE | 9 | The checkmate-flag is not set. |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
152 | INVALID_CHECK | 10 | The check-flag was incorrectly set. |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
153 | INVALID_CHECKMATE | 11 | The checkmate-flag was incorrectly set. |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
154 | RULES_VIOLATED | 32 | Other rules would be violated by this move. |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
155
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
156 ### End the Game
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
157
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
158 The active player, before making a move, SHALL determine if the game has ended.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
159 The game SHALL be ended if a [checkmate](#checkmate) or [stalemate](#stalemate)
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
160 position has been reached, or the [clock runs out](#clock-timeout).
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
161
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
162 The game SHOULD be ended if a draw can be [claimed](#claim-a-draw) due to a
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
163 threefold repetition of the same position, insufficient material, or playing
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
164 50 moves without any captures or pawn moves.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
165
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
166 The game MAY be ended at any time by any (including the waiting) player by
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
167 [resignation](#resign).
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
168
192
e57e2874fb2a fix how agreeing on a draw works
Mike Becker <universe@uap-core.de>
parents: 191
diff changeset
169 The game MAY also be ended after by agreeing on a [draw](#offer-a-draw).
e57e2874fb2a fix how agreeing on a draw works
Mike Becker <universe@uap-core.de>
parents: 191
diff changeset
170
191
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
171 #### Checkmate
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
172
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
173 Whe the active player determines they were checkmated with the last move,
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
174 they SHALL send a `CHECKMATE` message to the waiting player.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
175 When receiving such a message, the waiting player SHALL end the game without
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
176 sending any confirmation.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
177
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
178 #### Stalemate
186
8230904458a7 fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
179
191
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
180 When the active player determines a stalemate position, they SHALL send a
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
181 `STALEMATE` message to the waiting player.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
182 The waiting player SHOULD verify this claim.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
183 When verification fails, they SHALL send a `DECLINE` message, and they SHALL
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
184 send an `ACCEPT` message, otherwise.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
185
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
186 Both parties SHALL end the game when the stalemate was agreed on.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
187 Otherwise, both parties SHOULD continue playing.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
188
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
189 #### Clock Timeout
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
190
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
191 When the clock of the active player times out, they SHALL send a `TIMEOVER`
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
192 message to the waiting player.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
193 When receiving such a message, the waiting player SHALL end the game without
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
194 sending any confirmation.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
195
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
196 #### Claim a Draw
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
197
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
198 The active player SHOULD claim a draw, when
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
199 * the position is already repeated a third time (threefold repetition rule)
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
200 * there is not enough material for both players on the board (nobody can win)
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
201 * no capture or pawn move was made within the last 50 moves
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
202
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
203 The draw is claimed by sending a `THREEFOLD`, `NOMATERIAL`, or `50MOVES`
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
204 message, respectively.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
205 The waiting player SHOULD verify this claim.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
206 When verification fails, they SHALL send a `DECLINE` message, and they SHALL
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
207 send an `ACCEPT` message, otherwise.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
208
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
209 Both parties SHALL end the game when the draw was agreed on.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
210 Otherwise, both parties SHOULD continue playing.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
211
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
212 #### Resign
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
213
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
214 Both the active and the waiting player MAY send a `RESIGN` message any time.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
215 When a player receives a `RESIGN` message, they SHALL end the game without
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
216 any further confirmation.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
217
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
218 ### Offer a Draw
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
219
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
220 Both the active and the waiting player MAY send a `REMIS` message any time to
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
221 offer a draw.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
222
192
e57e2874fb2a fix how agreeing on a draw works
Mike Becker <universe@uap-core.de>
parents: 191
diff changeset
223 When both players have sent a `REMIS` message to the other player within the
e57e2874fb2a fix how agreeing on a draw works
Mike Becker <universe@uap-core.de>
parents: 191
diff changeset
224 same move, the draw is agreed upon and both players SHALL end the game.
191
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
225
192
e57e2874fb2a fix how agreeing on a draw works
Mike Becker <universe@uap-core.de>
parents: 191
diff changeset
226 Playing a move SHALL revoke any draw offers.
186
8230904458a7 fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
227
8230904458a7 fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
228 ### Propose Resignation
184
93c81539b702 fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents: 183
diff changeset
229
191
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
230 The waiting player MAY propose resignation by sending a `TAUNT` message.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
231
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
232 The active player MAY ignore such messages completely.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
233 Implementations MAY choose to display a message to the active player.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
234 If the active player decides to follow the proposal, they SHOULD send a
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
235 `RESIGN` message, as described [above](#resign).
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
236
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
237 The waiting player SHOULD NOT use this message excessively or inappropriately.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
238 It serves to inform the opponent about a decisive position and is intended to
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
239 encourage them to resign a lost game so that both players can make better use
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
240 of their time.
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
241
182
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242 ## Message Code Table
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 The following table shows the definitions of the network codes.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
245
191
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
246 | Code Name | Byte | With Payload |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
247 |--------------|------|--------------|
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
248 | ACCEPT | 0x01 | no |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
249 | DECLINE | 0x02 | no |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
250 | GAMEINFO | 0x10 | yes |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
251 | PGNDATA | 0x11 | yes |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
252 | MOVE | 0x20 | yes |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
253 | ACCEPT_MOVE | 0x21 | no |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
254 | DECLINE_MOVE | 0x22 | yes |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
255 | CHECKMATE | 0x30 | no |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
256 | STALEMATE | 0x31 | no |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
257 | NOMATERIAL | 0x32 | no |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
258 | THREEFOLD | 0x33 | no |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
259 | 50MOVES | 0x34 | no |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
260 | RESIGN | 0x41 | no |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
261 | REMIS | 0x42 | no |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
262 | TAUNT | 0x43 | no |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
263 | TIMEOVER | 0x44 | no |
182
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
264
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
265 The following codes are reserved for implementation.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
266 They are not used during transmissions and can be used as return values
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267 for functions to indicate errors.
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268
191
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
269 | Code Name | Byte |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
270 |-----------|------|
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
271 | AGAIN | 0x70 |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
272 | CONNLOST | 0x80 |
6da16865a270 complete documentation of the network protocol
Mike Becker <universe@uap-core.de>
parents: 188
diff changeset
273 | ERROR | 0xFF |
182
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
274
04c65336777f start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
diff changeset
275

mercurial