src/chess/rules.h

changeset 182
04c65336777f
parent 181
8bda076d0a16
equal deleted inserted replaced
181:8bda076d0a16 182:04c65336777f
89 uint64_t sec; 89 uint64_t sec;
90 int32_t usec; /* important that this is signed b/c potential carry */ 90 int32_t usec; /* important that this is signed b/c potential carry */
91 }; 91 };
92 92
93 typedef struct { 93 typedef struct {
94 char string[8];
95 struct movetimeval timestamp; /* TODO: remove this from the struct */
96 uint64_t movetime; /* the time for this move in microseconds */
94 Piece piece; 97 Piece piece;
95 File fromfile; 98 File fromfile;
96 Row fromrow; 99 Row fromrow;
97 File tofile; 100 File tofile;
98 Row torow; 101 Row torow;
99 Piece promotion; 102 Piece promotion;
100 uint8_t check; /* must always be set if checkmate is set */ 103 bool check; /* must always be set if checkmate is set */
101 uint8_t checkmate; 104 bool checkmate;
102 uint8_t capture; 105 bool capture;
103 uint8_t padding[7]; /* necessary for stable ABI across networks */
104 struct movetimeval timestamp; /* TODO: remove this from the struct */
105 uint64_t movetime; /* the time for this move in microseconds */
106 char string[8];
107 } Move; 106 } Move;
108 107
109 typedef struct { 108 typedef struct {
110 uint8_t servercolor; 109 uint8_t servercolor;
111 /** 1: play with timecontrol, 0: play without time control */ 110 /** 1: play with timecontrol, 0: play without time control */
487 * 486 *
488 * When short algebraic notation is used, the source position is determined by 487 * When short algebraic notation is used, the source position is determined by
489 * evaluating the allowed moves according to the current game state. 488 * evaluating the allowed moves according to the current game state.
490 * 489 *
491 * This function expects correct notation of check and checkmate indicators. 490 * This function expects correct notation of check and checkmate indicators.
492 * For a more lazy evaluation, use eval_move_lazy(). 491 * For a more lazy evaluation, use eval_move().
493 * 492 *
494 * For a purely syntactic check, regardless of whether a piece exists that is 493 * For a purely syntactic check, regardless of whether a piece exists that is
495 * allowed to move that way, use check_move(). 494 * allowed to move that way, use check_move().
496 * 495 *
497 * @param gamestate the current game state 496 * @param gamestate the current game state
498 * @param mstr the input string to parse 497 * @param mstr the input string to parse
499 * @param color the color of the player to evaluate the move for 498 * @param color the color of the player to evaluate the move for
500 * @param move a pointer to object where the move data shall be stored 499 * @param move a pointer to object where the move data shall be stored
501 * @return status code (see macros in this file for the list of codes) 500 * @return status code (see macros in this file for the list of codes)
502 */ 501 */
503 int eval_move(const GameState *gamestate, 502 int eval_move_strict(const GameState *gamestate,
504 const char *mstr, Color color, Move *move); 503 const char *mstr, Color color, Move *move);
505 504
506 /** 505 /**
507 * Evaluates a move syntactically and stores the move data in the specified 506 * Evaluates a move syntactically and stores the move data in the specified
508 * object. 507 * object.
509 * 508 *
510 * When short algebraic notation is used, the source position is determined by 509 * When short algebraic notation is used, the source position is determined by
511 * evaluating the allowed moves according to the current game state. 510 * evaluating the allowed moves according to the current game state.
512 * 511 *
513 * This function automatically corrects missing or incorrect check/checkmate 512 * This function automatically corrects missing or incorrect check/checkmate
514 * indicators. Use eval_move() if you want to keep the original notation. 513 * indicators. Use eval_move_strict() if you want to keep the original notation.
515 * 514 *
516 * For a purely syntactic check, regardless of whether a piece exists that is 515 * For a purely syntactic check, regardless of whether a piece exists that is
517 * allowed to move that way, use check_move(). 516 * allowed to move that way, use check_move().
518 * 517 *
519 * @param gamestate the current game state 518 * @param gamestate the current game state
520 * @param mstr the input string to parse 519 * @param mstr the input string to parse
521 * @param color the color of the player to evaluate the move for 520 * @param color the color of the player to evaluate the move for
522 * @param move a pointer to object where the move data shall be stored 521 * @param move a pointer to object where the move data shall be stored
523 * @return status code (see macros in this file for the list of codes) 522 * @return status code (see macros in this file for the list of codes)
524 */ 523 */
525 int eval_move_lazy(const GameState *gamestate, 524 int eval_move(const GameState *gamestate,
526 const char *mstr, Color color, Move *move); 525 const char *mstr, Color color, Move *move);
526
527 /**
528 * Calculates the move string within the specified move.
529 *
530 * This corrects any missing check / checkmate flags, first.
531 *
532 * Do not call this function after eval_move() or eval_move_strict().
533 *
534 * @param gamestate the current game state
535 * @param move the move data
536 */
537 void format_move(const GameState *gamestate, Move *move);
527 538
528 /** 539 /**
529 * Syntactically checks a move without verifying that a piece exists that is 540 * Syntactically checks a move without verifying that a piece exists that is
530 * allowed to move that way. 541 * allowed to move that way.
531 * 542 *

mercurial