src/chess/rules.h

changeset 131
c33567d61ba7
parent 130
3fc6b1d6cbe9
equal deleted inserted replaced
130:3fc6b1d6cbe9 131:c33567d61ba7
123 unsigned int movecount; 123 unsigned int movecount;
124 /** a premove that shall be evaluated next time it's our turn */ 124 /** a premove that shall be evaluated next time it's our turn */
125 char premove[8]; 125 char premove[8];
126 bool checkmate; 126 bool checkmate;
127 bool stalemate; 127 bool stalemate;
128 bool threefold;
128 bool remis; 129 bool remis;
129 bool wresign; 130 bool wresign;
130 bool bresign; 131 bool bresign;
131 /** this flag is only supposed to be set when the opponent disconnects */ 132 /** this flag is only supposed to be set when the opponent disconnects */
132 bool ragequit; 133 bool ragequit;
133 bool review; 134 bool review;
134 } GameState; 135 } GameState;
135 136
136 #define is_game_running(gamestate) !((gamestate)->checkmate || \ 137 #define is_game_running(gamestate) !((gamestate)->checkmate || \
137 (gamestate)->wresign || (gamestate)->bresign || \ 138 (gamestate)->wresign || (gamestate)->bresign || (gamestate)->threefold || \
138 (gamestate)->stalemate || (gamestate)->remis || (gamestate)->review) 139 (gamestate)->stalemate || (gamestate)->remis || (gamestate)->review)
139 140
140 #define last_move(gamestate) \ 141 #define last_move(gamestate) \
141 ((gamestate)->moves[(gamestate)->movecount-1]) 142 ((gamestate)->moves[(gamestate)->movecount-1])
142 143
393 * @param str the target buffer (should be at least 10 chars large) 394 * @param str the target buffer (should be at least 10 chars large)
394 * @param always_hours if hours should always be printed 395 * @param always_hours if hours should always be printed
395 */ 396 */
396 int print_clk(uint16_t time, char *str, bool always_hours); 397 int print_clk(uint16_t time, char *str, bool always_hours);
397 398
399 /**
400 * Checks if the current position already appeared two times before.
401 *
402 * This does not set the threefold flag in the game state as this flag is
403 * intended to be set only when the game ends after actually claiming a draw.
404 *
405 * By standard chess rules this is not automatically a draw.
406 * But implementation may choose to automatically draw the game anyway.
407 *
408 * @param gamestate the current game state
409 * @return true if the game is in a threefold repetition position
410 */
411 bool check_threefold_repetition(GameState *gamestate);
412
398 #endif /* RULES_H */ 413 #endif /* RULES_H */
399 414

mercurial