| 164 /** capacity of the move array */ |
164 /** capacity of the move array */ |
| 165 unsigned int movecapacity; |
165 unsigned int movecapacity; |
| 166 /** number of (half-)moves (counting BOTH colors) */ |
166 /** number of (half-)moves (counting BOTH colors) */ |
| 167 unsigned int movecount; |
167 unsigned int movecount; |
| 168 /** number of half-moves that have been played before reaching fen_start */ |
168 /** number of half-moves that have been played before reaching fen_start */ |
| 169 unsigned int move_start; // TODO: use this in board view and PGN export |
169 unsigned int move_start; |
| 170 /** number of half-moves w/o capture or pawn move played before fen_start */ |
170 /** number of half-moves w/o capture or pawn move played before fen_start */ |
| 171 unsigned int fifty_cntr_start; |
171 unsigned int fifty_cntr_start; |
| 172 /** a premove that shall be evaluated next time it's our turn */ |
172 /** a premove that shall be evaluated next time it's our turn */ |
| 173 char premove[8]; |
173 char premove[8]; |
| 174 bool checkmate; |
174 bool checkmate; |
| 208 |
208 |
| 209 static inline char rankchr(Rank rank) {return (char)rank+'1';} |
209 static inline char rankchr(Rank rank) {return (char)rank+'1';} |
| 210 static inline char filechr(File file) {return (char)file+'a';} |
210 static inline char filechr(File file) {return (char)file+'a';} |
| 211 |
211 |
| 212 |
212 |
| |
213 /** |
| |
214 * Returns the current move number. |
| |
215 * |
| |
216 * @param gamestate the current game state |
| |
217 * @return the full move number of the move that is next to play |
| |
218 */ |
| |
219 static inline unsigned move_number(const GameState *gamestate) { |
| |
220 return 1 + (gamestate->move_start + gamestate->movecount) / 2; |
| |
221 } |
| |
222 |
| |
223 /** |
| |
224 * Returns the current half-move number. |
| |
225 * |
| |
226 * The counter starts with one. |
| |
227 * |
| |
228 * @param gamestate the current game state |
| |
229 * @return the half-move number of the move that is next to play |
| |
230 */ |
| |
231 static inline unsigned move_number_half(const GameState *gamestate) { |
| |
232 return 1 + gamestate->move_start + gamestate->movecount; |
| |
233 } |
| |
234 |
| 213 static inline void enpassant_threat_add(GameState *gamestate, |
235 static inline void enpassant_threat_add(GameState *gamestate, |
| 214 File file, Rank rank) { |
236 File file, Rank rank) { |
| 215 gamestate->board[rank][file] |= ENPASSANT_THREAT; |
237 gamestate->board[rank][file] |= ENPASSANT_THREAT; |
| 216 } |
238 } |
| 217 |
239 |
| 239 if (gamestate->movecount == 0) return false; |
261 if (gamestate->movecount == 0) return false; |
| 240 return gamestate->moves[gamestate->movecount - 1].check; |
262 return gamestate->moves[gamestate->movecount - 1].check; |
| 241 } |
263 } |
| 242 |
264 |
| 243 static inline Color field_color(File f, Rank r) { |
265 static inline Color field_color(File f, Rank r) { |
| 244 return (r + f) % 2 == 0 ? BLACK : WHITE; |
266 return ((unsigned)r + (unsigned)f) % 2 == 0 ? BLACK : WHITE; |
| 245 } |
267 } |
| 246 |
268 |
| 247 /** |
269 /** |
| 248 * Initializes a game state and prepares the chess board. |
270 * Initializes a game state and prepares the chess board. |
| 249 * @param gamestate the game state to initialize |
271 * @param gamestate the game state to initialize |
| 292 * Returns the color of the player who is next to move. |
314 * Returns the color of the player who is next to move. |
| 293 * |
315 * |
| 294 * @param gamestate the current game state |
316 * @param gamestate the current game state |
| 295 * @return the color of the player who is next to move |
317 * @return the color of the player who is next to move |
| 296 */ |
318 */ |
| 297 Color current_color(const GameState *gamestate); |
319 static inline Color current_color(const GameState *gamestate) { |
| |
320 return move_number_half(gamestate) % 2 ? WHITE : BLACK; |
| |
321 } |
| 298 |
322 |
| 299 /** |
323 /** |
| 300 * Returns the piece at the specified position. |
324 * Returns the piece at the specified position. |
| 301 * |
325 * |
| 302 * @param gamestate the current game state |
326 * @param gamestate the current game state |