100 |
100 |
101 #define POS_UNSPECIFIED UINT8_MAX |
101 #define POS_UNSPECIFIED UINT8_MAX |
102 #define mdst(b,m) b[(m)->torow][(m)->tofile] |
102 #define mdst(b,m) b[(m)->torow][(m)->tofile] |
103 #define msrc(b,m) b[(m)->fromrow][(m)->fromfile] |
103 #define msrc(b,m) b[(m)->fromrow][(m)->fromfile] |
104 |
104 |
105 #define isidx(idx) ((uint8_t)idx < 8) |
105 #define isidx(idx) ((uint8_t)(idx) < 8) |
106 |
106 |
107 #define isfile(file) (file >= 'a' && file <= 'h') |
107 #define isfile(file) (file >= 'a' && file <= 'h') |
108 #define isrow(row) (row >= '1' && row <= '8') |
108 #define isrow(row) (row >= '1' && row <= '8') |
109 |
109 |
110 #define rowidx(row) (row-'1') |
110 #define rowidx(row) (row-'1') |
139 * |
139 * |
140 * @param piece one of ROOK, KNIGHT, BISHOP, QUEEN, KING |
140 * @param piece one of ROOK, KNIGHT, BISHOP, QUEEN, KING |
141 * @return character value for the specified piece |
141 * @return character value for the specified piece |
142 */ |
142 */ |
143 char getpiecechr(uint8_t piece); |
143 char getpiecechr(uint8_t piece); |
|
144 |
|
145 /** |
|
146 * Checks, if a specified field is covered by a piece of a certain color. |
|
147 * |
|
148 * Note: when the field is covered by multiple pieces, this function returns |
|
149 * the first piece it can find. |
|
150 * |
|
151 * @param gamestate the current game state |
|
152 * @param row row of the field to check |
|
153 * @param file file of the field to check |
|
154 * @param color the color of the piece that should threaten the field |
|
155 * @param threat if not NULL: a pointer to the move structure where |
|
156 * the move that could be performed to capture the field should be stored |
|
157 * @return TRUE, if any piece of the specified color threatens the specified |
|
158 * field (i.e. could capture an opponent piece) |
|
159 */ |
|
160 _Bool get_any_threat_for(GameState *gamestate, uint8_t row, uint8_t file, |
|
161 uint8_t color, Move *threat); |
144 |
162 |
145 /** |
163 /** |
146 * Checks, if a specified field is covered by a piece of a certain color. |
164 * Checks, if a specified field is covered by a piece of a certain color. |
147 * |
165 * |
148 * @param gamestate the current game state |
166 * @param gamestate the current game state |
150 * @param file file of the field to check |
168 * @param file file of the field to check |
151 * @param color the color of the piece that should cover the field |
169 * @param color the color of the piece that should cover the field |
152 * @return TRUE, if any piece of the specified color threatens the specified |
170 * @return TRUE, if any piece of the specified color threatens the specified |
153 * field (i.e. could capture an opponent piece) |
171 * field (i.e. could capture an opponent piece) |
154 */ |
172 */ |
155 _Bool is_covered(GameState *gamestate,uint8_t row,uint8_t file,uint8_t color); |
173 #define is_covered(gamestate, row, file, color) \ |
|
174 get_any_threat_for(gamestate, row, file, color, NULL) |
156 |
175 |
157 /** |
176 /** |
158 * Evaluates a move syntactically and stores the move data in the specified |
177 * Evaluates a move syntactically and stores the move data in the specified |
159 * object. |
178 * object. |
160 * |
179 * |