diff -r efeb98bc69c9 -r 0c1371488d87 src/chess/rules.h --- a/src/chess/rules.h Thu Apr 03 16:07:04 2014 +0200 +++ b/src/chess/rules.h Fri Apr 04 17:36:42 2014 +0200 @@ -102,7 +102,7 @@ #define mdst(b,m) b[(m)->torow][(m)->tofile] #define msrc(b,m) b[(m)->fromrow][(m)->fromfile] -#define isidx(idx) ((uint8_t)idx < 8) +#define isidx(idx) ((uint8_t)(idx) < 8) #define isfile(file) (file >= 'a' && file <= 'h') #define isrow(row) (row >= '1' && row <= '8') @@ -145,6 +145,24 @@ /** * Checks, if a specified field is covered by a piece of a certain color. * + * Note: when the field is covered by multiple pieces, this function returns + * the first piece it can find. + * + * @param gamestate the current game state + * @param row row of the field to check + * @param file file of the field to check + * @param color the color of the piece that should threaten the field + * @param threat if not NULL: a pointer to the move structure where + * the move that could be performed to capture the field should be stored + * @return TRUE, if any piece of the specified color threatens the specified + * field (i.e. could capture an opponent piece) + */ +_Bool get_any_threat_for(GameState *gamestate, uint8_t row, uint8_t file, + uint8_t color, Move *threat); + +/** + * Checks, if a specified field is covered by a piece of a certain color. + * * @param gamestate the current game state * @param row row of the field to check * @param file file of the field to check @@ -152,7 +170,8 @@ * @return TRUE, if any piece of the specified color threatens the specified * field (i.e. could capture an opponent piece) */ -_Bool is_covered(GameState *gamestate,uint8_t row,uint8_t file,uint8_t color); +#define is_covered(gamestate, row, file, color) \ + get_any_threat_for(gamestate, row, file, color, NULL) /** * Evaluates a move syntactically and stores the move data in the specified