src/chess/rules.h

changeset 50
41017d0a72c5
parent 49
02c509a44e98
child 55
54ea19938d57
equal deleted inserted replaced
49:02c509a44e98 50:41017d0a72c5
108 uint16_t addtime; 108 uint16_t addtime;
109 } GameInfo; 109 } GameInfo;
110 110
111 typedef struct { 111 typedef struct {
112 Board board; 112 Board board;
113 uint8_t mycolor;
114 MoveList* movelist; 113 MoveList* movelist;
115 MoveList* lastmove; 114 MoveList* lastmove;
116 _Bool checkmate; 115 _Bool checkmate;
117 _Bool stalemate; 116 _Bool stalemate;
117 _Bool remis;
118 _Bool resign;
118 } GameState; 119 } GameState;
119 120
120 #define opponent_color(color) ((color)==WHITE?BLACK:WHITE) 121 #define opponent_color(color) ((color)==WHITE?BLACK:WHITE)
121 122
122 #define POS_UNSPECIFIED UINT8_MAX 123 #define POS_UNSPECIFIED UINT8_MAX
138 isidx((move)->tofile) && isidx((move)->torow)) 139 isidx((move)->tofile) && isidx((move)->torow))
139 140
140 /* secure versions - use, if index is not checked with isidx() */ 141 /* secure versions - use, if index is not checked with isidx() */
141 #define fileidx_s(c) (isfile(c)?fileidx(c):POS_UNSPECIFIED) 142 #define fileidx_s(c) (isfile(c)?fileidx(c):POS_UNSPECIFIED)
142 #define rowidx_s(c) (isrow(c)?rowidx(c):POS_UNSPECIFIED) 143 #define rowidx_s(c) (isrow(c)?rowidx(c):POS_UNSPECIFIED)
144
145 #define is_game_running(gamestate) !((gamestate)->checkmate || \
146 (gamestate)->resign || (gamestate)->stalemate || (gamestate)->remis)
147
148
149 /**
150 * Initializes a game state and prepares the chess board.
151 * @param gamestate the game state to initialize
152 */
153 void gamestate_init(GameState *gamestate);
143 154
144 /** 155 /**
145 * Cleans up a game state and frees the memory for the movement list. 156 * Cleans up a game state and frees the memory for the movement list.
146 * @param gamestate the game state to clean up 157 * @param gamestate the game state to clean up
147 */ 158 */
274 * object. 285 * object.
275 * 286 *
276 * @param gamestate the current game state 287 * @param gamestate the current game state
277 * @param mstr the input string to parse 288 * @param mstr the input string to parse
278 * @param move a pointer to object where the move data shall be stored 289 * @param move a pointer to object where the move data shall be stored
290 * @param color the color of the player to evaluate the move for
279 * @return status code (see macros in this file for the list of codes) 291 * @return status code (see macros in this file for the list of codes)
280 */ 292 */
281 int eval_move(GameState *gamestate, char *mstr, Move *move); 293 int eval_move(GameState *gamestate, char *mstr, Move *move, uint8_t color);
282 294
283 /** 295 /**
284 * Validates move by applying chess rules. 296 * Validates move by applying chess rules.
285 * @param gamestate the current game state 297 * @param gamestate the current game state
286 * @param move the move to validate 298 * @param move the move to validate

mercurial