src/chess/rules.h

changeset 29
c6a1ad6cf749
parent 28
0c1371488d87
child 30
a285ee393860
     1.1 --- a/src/chess/rules.h	Fri Apr 04 17:36:42 2014 +0200
     1.2 +++ b/src/chess/rules.h	Mon Apr 07 14:08:57 2014 +0200
     1.3 @@ -145,20 +145,41 @@
     1.4  /**
     1.5   * Checks, if a specified field is covered by a piece of a certain color.
     1.6   * 
     1.7 - * Note: when the field is covered by multiple pieces, this function returns
     1.8 - * the first piece it can find.
     1.9 + * The out-parameters may both be NULL, but if any of them is set, the other
    1.10 + * must be set, too.
    1.11   * 
    1.12   * @param gamestate the current game state
    1.13   * @param row row of the field to check
    1.14   * @param file file of the field to check
    1.15   * @param color the color of the piece that should threaten the field
    1.16 - * @param threat if not NULL: a pointer to the move structure where
    1.17 - * the move that could be performed to capture the field should be stored
    1.18 + * @param threats the array where to store the threats (should be able to the
    1.19 + * rare maximum of 16 elements)
    1.20 + * @param threatcount a pointer to an uint8_t where to store the amount of threats
    1.21   * @return TRUE, if any piece of the specified color threatens the specified
    1.22   * field (i.e. could capture an opponent piece)
    1.23   */
    1.24 -_Bool get_any_threat_for(GameState *gamestate, uint8_t row, uint8_t file,
    1.25 -        uint8_t color, Move *threat);
    1.26 +_Bool get_threats(GameState *gamestate, uint8_t row, uint8_t file,
    1.27 +        uint8_t color, Move* threats, uint8_t* threatcount);
    1.28 +
    1.29 +/**
    1.30 + * Checks, if a specified field is covered by a piece of a certain color AND
    1.31 + * if this piece is not pinned and therefore able to perform the move.
    1.32 + * 
    1.33 + * The out-parameters may both be NULL, but if any of them is set, the other
    1.34 + * must be set, too.
    1.35 + * 
    1.36 + * @param gamestate the current game state
    1.37 + * @param row row of the field to check
    1.38 + * @param file file of the field to check
    1.39 + * @param color the color of the piece that should threaten the field
    1.40 + * @param threats the array where to store the threats (should be able to the
    1.41 + * rare maximum of 16 elements)
    1.42 + * @param threatcount a pointer to an uint8_t where to store the amount of threats
    1.43 + * @return TRUE, if any piece of the specified color threatens the specified
    1.44 + * field (i.e. could capture an opponent piece)
    1.45 + */
    1.46 +_Bool get_real_threats(GameState *gamestate, uint8_t row, uint8_t file,
    1.47 +        uint8_t color, Move* threats, uint8_t* threatcount);
    1.48  
    1.49  /**
    1.50   * Checks, if a specified field is covered by a piece of a certain color.
    1.51 @@ -168,10 +189,42 @@
    1.52   * @param file file of the field to check
    1.53   * @param color the color of the piece that should cover the field
    1.54   * @return TRUE, if any piece of the specified color threatens the specified
    1.55 - * field (i.e. could capture an opponent piece)
    1.56 + * field
    1.57   */
    1.58  #define is_covered(gamestate, row, file, color) \
    1.59 -    get_any_threat_for(gamestate, row, file, color, NULL)
    1.60 +    get_threats(gamestate, row, file, color, NULL, NULL)
    1.61 +
    1.62 +/**
    1.63 + * Checks, if a specified field is attacked by a piece of a certain color.
    1.64 + * 
    1.65 + * I.e. the field is covered by a piece AND this piece is not pinned and
    1.66 + * therefore able to perform the move.
    1.67 + * 
    1.68 + * @param gamestate the current game state
    1.69 + * @param row row of the field to check
    1.70 + * @param file file of the field to check
    1.71 + * @param color the color of the piece that should cover the field
    1.72 + * @return TRUE, if any piece of the specified color threatens the specified
    1.73 + * field and could capture an opponent piece
    1.74 + */
    1.75 +#define is_attacked(gamestate, row, file, color) \
    1.76 +    get_threats(gamestate, row, file, color, NULL, NULL)
    1.77 +
    1.78 +/**
    1.79 + * Checks, if a specified field is protected by a piece of a certain color.
    1.80 + * 
    1.81 + * I.e. the field is covered by a piece that is NOT the king AND this piece is
    1.82 + * not pinned and therefore able to perform the move.
    1.83 + * 
    1.84 + * @param gamestate the current game state
    1.85 + * @param row row of the field to check
    1.86 + * @param file file of the field to check
    1.87 + * @param color the color of the piece that should cover the field
    1.88 + * @return TRUE, if any piece (excluding the king) of the specified color
    1.89 + * threatens the specified field and could capture an opponent piece
    1.90 + */
    1.91 +_Bool is_protected(GameState *gamestate, uint8_t row, uint8_t file,
    1.92 +        uint8_t color);
    1.93  
    1.94  /**
    1.95   * Evaluates a move syntactically and stores the move data in the specified

mercurial