src/chess/rules.h

changeset 161
3ff96fec144a
parent 160
f87832cba8b8
child 163
2a6d83f4677e
equal deleted inserted replaced
160:f87832cba8b8 161:3ff96fec144a
148 148
149 #define piece_type(piece) ((piece)&PIECE_MASK) 149 #define piece_type(piece) ((piece)&PIECE_MASK)
150 #define piece_color(piece) ((piece)&COLOR_MASK) 150 #define piece_color(piece) ((piece)&COLOR_MASK)
151 #define mkpiece(type,color) ((type)|(color)) 151 #define mkpiece(type,color) ((type)|(color))
152 152
153 #define enpassant_threat_add(gamestate, row, file) \
154 (gamestate->board[row][file] |= ENPASSANT_THREAT)
155 #define enpassant_threat_remove(gamestate, row, file) \
156 (gamestate->board[row][file] &= ~ENPASSANT_THREAT)
157 #define enpassant_threat_exists(gamestate, row, file) \
158 (gamestate->board[row][file] & ENPASSANT_THREAT)
159
160 #define is_game_running(gamestate) !((gamestate)->checkmate || \
161 (gamestate)->wresign || (gamestate)->bresign || (gamestate)->threefold || \
162 (gamestate)->stalemate || (gamestate)->remis || (gamestate)->review)
163
164 #define last_move(gamestate) \
165 ((gamestate)->moves[(gamestate)->movecount-1])
166
167 #define POS_UNSPECIFIED UINT8_MAX 153 #define POS_UNSPECIFIED UINT8_MAX
168 #define mdst(m) (m)->torow, (m)->tofile 154 #define mdst(m) (m)->torow, (m)->tofile
169 #define msrc(m) (m)->fromrow, (m)->fromfile 155 #define msrc(m) (m)->fromrow, (m)->fromfile
170 156
171 /** Checks if the index is specified and valid. */ 157 /** Checks if the index is specified and valid. */
183 #define filechr(file) (file+'a') 169 #define filechr(file) (file+'a')
184 170
185 /* secure versions - use, if index is not checked with isidx() */ 171 /* secure versions - use, if index is not checked with isidx() */
186 #define fileidx_s(c) (isfile(c)?fileidx(c):POS_UNSPECIFIED) 172 #define fileidx_s(c) (isfile(c)?fileidx(c):POS_UNSPECIFIED)
187 #define rowidx_s(c) (isrow(c)?rowidx(c):POS_UNSPECIFIED) 173 #define rowidx_s(c) (isrow(c)?rowidx(c):POS_UNSPECIFIED)
174
175
176 static inline void enpassant_threat_add(GameState *gamestate,
177 Row row, File file) {
178 gamestate->board[row][file] |= ENPASSANT_THREAT;
179 }
180
181 static inline void enpassant_threat_remove(GameState *gamestate,
182 Row row, File file) {
183 gamestate->board[row][file] &= ~ENPASSANT_THREAT;
184 }
185
186 static inline bool enpassant_threat_exists(const GameState *gamestate,
187 Row row, File file) {
188 return gamestate->board[row][file] & ENPASSANT_THREAT;
189 }
190
191 static inline bool is_game_running(const GameState *gamestate) {
192 return !(gamestate->checkmate || gamestate->wresign || gamestate->bresign || gamestate->threefold || gamestate->stalemate || gamestate->remis || gamestate->review);
193 }
188 194
189 /** 195 /**
190 * Initializes a game state and prepares the chess board. 196 * Initializes a game state and prepares the chess board.
191 * @param gamestate the game state to initialize 197 * @param gamestate the game state to initialize
192 */ 198 */

mercurial