src/chess/rules.h

changeset 28
0c1371488d87
parent 27
efeb98bc69c9
child 29
c6a1ad6cf749
     1.1 --- a/src/chess/rules.h	Thu Apr 03 16:07:04 2014 +0200
     1.2 +++ b/src/chess/rules.h	Fri Apr 04 17:36:42 2014 +0200
     1.3 @@ -102,7 +102,7 @@
     1.4  #define mdst(b,m) b[(m)->torow][(m)->tofile]
     1.5  #define msrc(b,m) b[(m)->fromrow][(m)->fromfile]
     1.6  
     1.7 -#define isidx(idx) ((uint8_t)idx < 8)
     1.8 +#define isidx(idx) ((uint8_t)(idx) < 8)
     1.9  
    1.10  #define isfile(file) (file >= 'a' && file <= 'h')
    1.11  #define isrow(row) (row >= '1' && row <= '8')
    1.12 @@ -145,6 +145,24 @@
    1.13  /**
    1.14   * Checks, if a specified field is covered by a piece of a certain color.
    1.15   * 
    1.16 + * Note: when the field is covered by multiple pieces, this function returns
    1.17 + * the first piece it can find.
    1.18 + * 
    1.19 + * @param gamestate the current game state
    1.20 + * @param row row of the field to check
    1.21 + * @param file file of the field to check
    1.22 + * @param color the color of the piece that should threaten the field
    1.23 + * @param threat if not NULL: a pointer to the move structure where
    1.24 + * the move that could be performed to capture the field should be stored
    1.25 + * @return TRUE, if any piece of the specified color threatens the specified
    1.26 + * field (i.e. could capture an opponent piece)
    1.27 + */
    1.28 +_Bool get_any_threat_for(GameState *gamestate, uint8_t row, uint8_t file,
    1.29 +        uint8_t color, Move *threat);
    1.30 +
    1.31 +/**
    1.32 + * Checks, if a specified field is covered by a piece of a certain color.
    1.33 + * 
    1.34   * @param gamestate the current game state
    1.35   * @param row row of the field to check
    1.36   * @param file file of the field to check
    1.37 @@ -152,7 +170,8 @@
    1.38   * @return TRUE, if any piece of the specified color threatens the specified
    1.39   * field (i.e. could capture an opponent piece)
    1.40   */
    1.41 -_Bool is_covered(GameState *gamestate,uint8_t row,uint8_t file,uint8_t color);
    1.42 +#define is_covered(gamestate, row, file, color) \
    1.43 +    get_any_threat_for(gamestate, row, file, color, NULL)
    1.44  
    1.45  /**
    1.46   * Evaluates a move syntactically and stores the move data in the specified

mercurial