diff -r 0c1371488d87 -r c6a1ad6cf749 src/chess/rules.h --- a/src/chess/rules.h Fri Apr 04 17:36:42 2014 +0200 +++ b/src/chess/rules.h Mon Apr 07 14:08:57 2014 +0200 @@ -145,20 +145,41 @@ /** * 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. + * The out-parameters may both be NULL, but if any of them is set, the other + * must be set, too. * * @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 + * @param threats the array where to store the threats (should be able to the + * rare maximum of 16 elements) + * @param threatcount a pointer to an uint8_t where to store the amount of threats * @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); +_Bool get_threats(GameState *gamestate, uint8_t row, uint8_t file, + uint8_t color, Move* threats, uint8_t* threatcount); + +/** + * Checks, if a specified field is covered by a piece of a certain color AND + * if this piece is not pinned and therefore able to perform the move. + * + * The out-parameters may both be NULL, but if any of them is set, the other + * must be set, too. + * + * @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 threats the array where to store the threats (should be able to the + * rare maximum of 16 elements) + * @param threatcount a pointer to an uint8_t where to store the amount of threats + * @return TRUE, if any piece of the specified color threatens the specified + * field (i.e. could capture an opponent piece) + */ +_Bool get_real_threats(GameState *gamestate, uint8_t row, uint8_t file, + uint8_t color, Move* threats, uint8_t* threatcount); /** * Checks, if a specified field is covered by a piece of a certain color. @@ -168,10 +189,42 @@ * @param file file of the field to check * @param color the color of the piece that should cover the field * @return TRUE, if any piece of the specified color threatens the specified - * field (i.e. could capture an opponent piece) + * field */ #define is_covered(gamestate, row, file, color) \ - get_any_threat_for(gamestate, row, file, color, NULL) + get_threats(gamestate, row, file, color, NULL, NULL) + +/** + * Checks, if a specified field is attacked by a piece of a certain color. + * + * I.e. the field is covered by a piece AND this piece is not pinned and + * therefore able to perform the move. + * + * @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 cover the field + * @return TRUE, if any piece of the specified color threatens the specified + * field and could capture an opponent piece + */ +#define is_attacked(gamestate, row, file, color) \ + get_threats(gamestate, row, file, color, NULL, NULL) + +/** + * Checks, if a specified field is protected by a piece of a certain color. + * + * I.e. the field is covered by a piece that is NOT the king AND this piece is + * not pinned and therefore able to perform the move. + * + * @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 cover the field + * @return TRUE, if any piece (excluding the king) of the specified color + * threatens the specified field and could capture an opponent piece + */ +_Bool is_protected(GameState *gamestate, uint8_t row, uint8_t file, + uint8_t color); /** * Evaluates a move syntactically and stores the move data in the specified