diff -r 41bbfd4d17a3 -r 824c9522ce66 src/chess/rules.h --- a/src/chess/rules.h Mon Mar 31 14:08:00 2014 +0200 +++ b/src/chess/rules.h Mon Mar 31 15:03:25 2014 +0200 @@ -68,6 +68,7 @@ typedef uint8_t Board[8][8]; + typedef struct { uint8_t piece; uint8_t fromfile; @@ -80,6 +81,20 @@ _Bool capture; } Move; +typedef struct MoveList MoveList; + +struct MoveList { + Move move; + MoveList* next; +}; + +typedef struct { + Board board; + uint8_t mycolor; + MoveList* movelist; + MoveList* lastmove; +} GameState; + #define POS_UNSPECIFIED UINT8_MAX #define mdst(b,m) b[(m)->torow][(m)->tofile] #define msrc(b,m) b[(m)->fromrow][(m)->fromfile] @@ -102,6 +117,8 @@ #define fileidx_s(c) (isfile(c)?fileidx(c):POS_UNSPECIFIED) #define rowidx_s(c) (isrow(c)?rowidx(c):POS_UNSPECIFIED) +void gamestate_cleanup(GameState *gamestate); + /** * Maps a character to a piece. * @@ -126,29 +143,28 @@ * Evaluates a move syntactically and stores the move data in the specified * object. * - * @param board the current state of the board - * @param mycolor the color of the current player + * @param gamestate the current game state * @param mstr the input string to parse * @param move a pointer to object where the move data shall be stored * @return status code (see rules/rules.h for the list of codes) */ -int eval_move(Board board, uint8_t mycolor, char *mstr, Move *move); +int eval_move(GameState *gamestate, char *mstr, Move *move); /** * Validates move by applying chess rules. - * @param board the current board state + * @param gamestate the current game state * @param move the move to validate * @return TRUE, if the move complies to chess rules, FALSE otherwise */ -_Bool validate_move(Board board, Move *move); +_Bool validate_move(GameState *gamestate, Move *move); /** * Applies a move and deletes captured pieces. * - * @param board the current board state + * @param gamestate the current game state * @param move the move to apply */ -void apply_move(Board board, Move *move); +void apply_move(GameState *gamestate, Move *move); #endif /* RULES_H */