src/chess/rules.h

changeset 23
824c9522ce66
parent 19
6a26114297a1
child 25
3ab0c2e1a4e2
     1.1 --- a/src/chess/rules.h	Mon Mar 31 14:08:00 2014 +0200
     1.2 +++ b/src/chess/rules.h	Mon Mar 31 15:03:25 2014 +0200
     1.3 @@ -68,6 +68,7 @@
     1.4  
     1.5  typedef uint8_t Board[8][8];
     1.6  
     1.7 +
     1.8  typedef struct {
     1.9      uint8_t piece;
    1.10      uint8_t fromfile;
    1.11 @@ -80,6 +81,20 @@
    1.12      _Bool capture;
    1.13  } Move;
    1.14  
    1.15 +typedef struct MoveList MoveList;
    1.16 +
    1.17 +struct MoveList {
    1.18 +    Move move;
    1.19 +    MoveList* next;
    1.20 +};
    1.21 +
    1.22 +typedef struct {
    1.23 +    Board board;
    1.24 +    uint8_t mycolor;
    1.25 +    MoveList* movelist;
    1.26 +    MoveList* lastmove;
    1.27 +} GameState;
    1.28 +
    1.29  #define POS_UNSPECIFIED UINT8_MAX
    1.30  #define mdst(b,m) b[(m)->torow][(m)->tofile]
    1.31  #define msrc(b,m) b[(m)->fromrow][(m)->fromfile]
    1.32 @@ -102,6 +117,8 @@
    1.33  #define fileidx_s(c) (isfile(c)?fileidx(c):POS_UNSPECIFIED)
    1.34  #define rowidx_s(c) (isrow(c)?rowidx(c):POS_UNSPECIFIED)
    1.35  
    1.36 +void gamestate_cleanup(GameState *gamestate);
    1.37 +
    1.38  /**
    1.39   * Maps a character to a piece.
    1.40   * 
    1.41 @@ -126,29 +143,28 @@
    1.42   * Evaluates a move syntactically and stores the move data in the specified
    1.43   * object.
    1.44   * 
    1.45 - * @param board the current state of the board
    1.46 - * @param mycolor the color of the current player
    1.47 + * @param gamestate the current game state
    1.48   * @param mstr the input string to parse
    1.49   * @param move a pointer to object where the move data shall be stored
    1.50   * @return status code (see rules/rules.h for the list of codes)
    1.51   */
    1.52 -int eval_move(Board board, uint8_t mycolor, char *mstr, Move *move);
    1.53 +int eval_move(GameState *gamestate, char *mstr, Move *move);
    1.54  
    1.55  /**
    1.56   * Validates move by applying chess rules.
    1.57 - * @param board the current board state
    1.58 + * @param gamestate the current game state
    1.59   * @param move the move to validate
    1.60   * @return TRUE, if the move complies to chess rules, FALSE otherwise
    1.61   */
    1.62 -_Bool validate_move(Board board, Move *move);
    1.63 +_Bool validate_move(GameState *gamestate, Move *move);
    1.64  
    1.65  /**
    1.66   * Applies a move and deletes captured pieces.
    1.67   * 
    1.68 - * @param board the current board state
    1.69 + * @param gamestate the current game state
    1.70   * @param move the move to apply
    1.71   */
    1.72 -void apply_move(Board board, Move *move);
    1.73 +void apply_move(GameState *gamestate, Move *move);
    1.74  
    1.75  #endif	/* RULES_H */
    1.76  

mercurial