| 274 static inline void piece_remove(GameState *gamestate, Row row, File file) { |
286 static inline void piece_remove(GameState *gamestate, Row row, File file) { |
| 275 piece_set(gamestate, row, file, 0); |
287 piece_set(gamestate, row, file, 0); |
| 276 } |
288 } |
| 277 |
289 |
| 278 /** |
290 /** |
| 279 * Checks, if a specified field is covered by a piece of a certain color. |
291 * Determines a list of possible moves to the specified field. |
| |
292 * |
| |
293 * The out-parameters may both be NULL, but if any of them is set, the other |
| |
294 * must be set, too. |
| |
295 * |
| |
296 * @param gamestate the current game state |
| |
297 * @param row row of the field to check |
| |
298 * @param file file of the field to check |
| |
299 * @param color the color of the piece that should move to the field |
| |
300 * @param moves the array where to store the moves |
| |
301 * (must be large enough, 16 is always enough) |
| |
302 * @param movecount a pointer where the number of moves is stored |
| |
303 * @return true, if any piece of the specified color can move to the specified |
| |
304 * field |
| |
305 */ |
| |
306 bool get_candidates(const GameState *gamestate, Row row, File file, |
| |
307 Color color, Move* moves, size_t* movecount); |
| |
308 |
| |
309 /** |
| |
310 * Checks, if a specified field is threatened by a piece of a certain color. |
| |
311 * |
| |
312 * A field is threatened, if there is a piece of the specified color that could |
| |
313 * capture an opponent piece on this field, regardless of being pinned. |
| 280 * |
314 * |
| 281 * The out-parameters may both be NULL, but if any of them is set, the other |
315 * The out-parameters may both be NULL, but if any of them is set, the other |
| 282 * must be set, too. |
316 * must be set, too. |
| 283 * |
317 * |
| 284 * @param gamestate the current game state |
318 * @param gamestate the current game state |
| 285 * @param row row of the field to check |
319 * @param row row of the field to check |
| 286 * @param file file of the field to check |
320 * @param file file of the field to check |
| 287 * @param color the color of the piece that should threaten the field |
321 * @param color the color of the piece that should threaten the field |
| 288 * @param threats the array where to store the threats (should be able to hold |
322 * @param threats the array where to store the threats |
| 289 * the rare maximum of 16 elements) |
323 * (must be large enough, 16 is always enough) |
| 290 * @param threatcount a pointer where the count of threats is stored |
324 * @param threatcount a pointer where the count of threats is stored |
| 291 * @return true, if any piece of the specified color threatens the specified |
325 * @return true, if any piece of the specified color threatens the specified |
| 292 * field (i.e. could capture an opponent piece) |
326 * field |
| 293 */ |
327 */ |
| 294 bool get_threats(GameState *gamestate, Row row, File file, |
328 bool get_threats(const GameState *gamestate, Row row, File file, |
| 295 Color color, Move* threats, size_t* threatcount); |
329 Color color, Move* threats, size_t* threatcount); |
| 296 |
330 |
| 297 /** |
331 /** |
| 298 * Checks, if a specified field is covered by a piece of a certain color AND |
332 * Checks, if a specified field is threatened by a piece of a certain color AND |
| 299 * if this piece is not pinned and therefore able to perform the move. |
333 * if this piece is not pinned and therefore able to perform the move. |
| 300 * |
334 * |
| 301 * The out-parameters may both be NULL, but if any of them is set, the other |
335 * The out-parameters may both be NULL, but if any of them is set, the other |
| 302 * must be set, too. |
336 * must be set, too. |
| 303 * |
337 * |
| 304 * @param gamestate the current game state |
338 * @param gamestate the current game state |
| 305 * @param row row of the field to check |
339 * @param row row of the field to check |
| 306 * @param file file of the field to check |
340 * @param file file of the field to check |
| 307 * @param color the color of the piece that should threaten the field |
341 * @param color the color of the piece that should threaten the field |
| 308 * @param threats the array where to store the threats (should be able to hold |
342 * @param threats the array where to store the threats |
| 309 * the rare maximum of 16 elements) |
343 * (must be large enough, 16 is always enough) |
| 310 * @param threatcount a pointer where the count of threats is stored |
344 * @param threatcount a pointer where the count of threats is stored |
| 311 * @return true, if any piece of the specified color threatens the specified |
345 * @return true, if any piece of the specified color threatens the specified |
| 312 * field (i.e. could capture an opponent piece) |
346 * field and is not pinned |
| 313 */ |
347 */ |
| 314 bool get_real_threats(GameState *gamestate, Row row, File file, |
348 bool get_real_threats(const GameState *gamestate, Row row, File file, |
| 315 Color color, Move* threats, size_t* threatcount); |
349 Color color, Move* threats, size_t* threatcount); |
| 316 |
350 |
| 317 /** |
351 /** |
| 318 * Checks, if a specified field is covered by a piece of a certain color. |
352 * Checks, if a specified field is threatened by a piece of a certain color. |
| |
353 * |
| |
354 * A field is threatened, if there is a piece of the specified color that could |
| |
355 * capture an opponent piece on this field, regardless of being pinned. |
| 319 * |
356 * |
| 320 * @param gamestate the current game state |
357 * @param gamestate the current game state |
| 321 * @param row row of the field to check |
358 * @param row row of the field to check |
| 322 * @param file file of the field to check |
359 * @param file file of the field to check |
| 323 * @param color the color of the piece that should cover the field |
360 * @param color the color of the piece that should cover the field |
| 344 get_real_threats(gamestate, row, file, color, NULL, NULL) |
381 get_real_threats(gamestate, row, file, color, NULL, NULL) |
| 345 |
382 |
| 346 /** |
383 /** |
| 347 * Checks, if a specified field is protected by a piece of a certain color. |
384 * Checks, if a specified field is protected by a piece of a certain color. |
| 348 * |
385 * |
| 349 * I.e. the field is covered by a piece that is NOT the king AND this piece is |
386 * This is the same as is_attacked(), but only considers pieces that are not |
| 350 * not pinned and therefore able to perform the move. |
387 * the king. |
| 351 * |
388 * |
| 352 * @param gamestate the current game state |
389 * @param gamestate the current game state |
| 353 * @param row row of the field to check |
390 * @param row row of the field to check |
| 354 * @param file file of the field to check |
391 * @param file file of the field to check |
| 355 * @param color the color of the piece that should cover the field |
392 * @param color the color of the piece that should cover the field |
| 356 * @return true, if any piece (excluding the king) of the specified color |
393 * @return true, if any piece (excluding the king) of the specified color |
| 357 * threatens the specified field and could capture an opponent piece |
394 * threatens the specified field and could capture an opponent piece |
| 358 */ |
395 */ |
| 359 bool is_protected(GameState *gamestate, Row row, File file, Color color); |
396 bool is_protected(const GameState *gamestate, Row row, File file, Color color); |
| 360 |
397 |
| 361 /** |
398 /** |
| 362 * Checks, if the specified move cannot be performed, because the piece is |
399 * Checks, if the specified move cannot be performed, because the piece is |
| 363 * either pinned or cannot remove the check. |
400 * either pinned or cannot remove the check. |
| 364 * |
401 * |
| 370 * @param gamestate the current game state |
407 * @param gamestate the current game state |
| 371 * @param move the move to check |
408 * @param move the move to check |
| 372 * @return true, if the move cannot be performed because the king would be in |
409 * @return true, if the move cannot be performed because the king would be in |
| 373 * check after the move |
410 * check after the move |
| 374 */ |
411 */ |
| 375 bool is_pinned(GameState *gamestate, Move *move); |
412 bool is_pinned(const GameState *gamestate, const Move *move); |
| 376 |
413 |
| 377 /** |
414 /** |
| 378 * Evaluates a move syntactically and stores the move data in the specified |
415 * Evaluates a move syntactically and stores the move data in the specified |
| 379 * object. |
416 * object. |
| 380 * |
417 * |
| 381 * When short algebraic notation is used, the source position is determined by |
418 * When short algebraic notation is used, the source position is determined by |
| 382 * the evaluating the allowed moves according to the current game state. |
419 * evaluating the allowed moves according to the current game state. |
| |
420 * |
| |
421 * This function expects correct notation of check and checkmate indicators. |
| |
422 * For a more lazy evaluation, use eval_move_lazy(). |
| 383 * |
423 * |
| 384 * For a purely syntactic check, regardless of whether a piece exists that is |
424 * For a purely syntactic check, regardless of whether a piece exists that is |
| 385 * allowed to move that way, use check_move(). |
425 * allowed to move that way, use check_move(). |
| 386 * |
426 * |
| 387 * @param gamestate the current game state |
427 * @param gamestate the current game state |
| 388 * @param mstr the input string to parse |
428 * @param mstr the input string to parse |
| |
429 * @param color the color of the player to evaluate the move for |
| 389 * @param move a pointer to object where the move data shall be stored |
430 * @param move a pointer to object where the move data shall be stored |
| |
431 * @return status code (see macros in this file for the list of codes) |
| |
432 */ |
| |
433 int eval_move(const GameState *gamestate, |
| |
434 const char *mstr, Color color, Move *move); |
| |
435 |
| |
436 /** |
| |
437 * Evaluates a move syntactically and stores the move data in the specified |
| |
438 * object. |
| |
439 * |
| |
440 * When short algebraic notation is used, the source position is determined by |
| |
441 * evaluating the allowed moves according to the current game state. |
| |
442 * |
| |
443 * This function automatically corrects missing or incorrect check/checkmate |
| |
444 * indicators. Use eval_move() if you want to keep the original notation. |
| |
445 * |
| |
446 * For a purely syntactic check, regardless of whether a piece exists that is |
| |
447 * allowed to move that way, use check_move(). |
| |
448 * |
| |
449 * @param gamestate the current game state |
| |
450 * @param mstr the input string to parse |
| 390 * @param color the color of the player to evaluate the move for |
451 * @param color the color of the player to evaluate the move for |
| |
452 * @param move a pointer to object where the move data shall be stored |
| 391 * @return status code (see macros in this file for the list of codes) |
453 * @return status code (see macros in this file for the list of codes) |
| 392 */ |
454 */ |
| 393 int eval_move(GameState *gamestate, const char *mstr, Move *move, Color color); |
455 int eval_move_lazy(const GameState *gamestate, |
| |
456 const char *mstr, Color color, Move *move); |
| 394 |
457 |
| 395 /** |
458 /** |
| 396 * Syntactically checks a move without verifying that a piece exists that is |
459 * Syntactically checks a move without verifying that a piece exists that is |
| 397 * allowed to move that way. |
460 * allowed to move that way. |
| 398 * |
461 * |
| 437 * @param gamestate the current game state |
500 * @param gamestate the current game state |
| 438 * @param move_number the half-move that is now going to be played |
501 * @param move_number the half-move that is now going to be played |
| 439 * @return the remaining time - if time control is disabled, this function |
502 * @return the remaining time - if time control is disabled, this function |
| 440 * always returns zero |
503 * always returns zero |
| 441 */ |
504 */ |
| 442 uint16_t remaining_movetime2(GameState *gamestate, unsigned move_number); |
505 uint16_t remaining_movetime2(const GameState *gamestate, unsigned move_number); |
| 443 |
506 |
| 444 /** |
507 /** |
| 445 * Returns the remaining time on the clock for the specified player. |
508 * Returns the remaining time on the clock for the specified player. |
| 446 * |
509 * |
| 447 * @param gamestate the current game state |
510 * @param gamestate the current game state |
| 448 * @param color either BLACK or WHITE |
511 * @param color either BLACK or WHITE |
| 449 * @return the remaining time - if time control is disabled, this function |
512 * @return the remaining time - if time control is disabled, this function |
| 450 * always returns zero |
513 * always returns zero |
| 451 */ |
514 */ |
| 452 uint16_t remaining_movetime(GameState *gamestate, Color color); |
515 uint16_t remaining_movetime(const GameState *gamestate, Color color); |
| 453 |
516 |
| 454 /** |
517 /** |
| 455 * Converts clock time to string. |
518 * Converts clock time to string. |
| 456 * |
519 * |
| 457 * @param time the time to format |
520 * @param time the time to format |