src/chess/rules.h

changeset 47
d726e4b46c33
parent 41
a8346dcf7bbf
child 48
0cedda2544da
equal deleted inserted replaced
46:4dcfb4c58b6d 47:d726e4b46c33
36 #define VALID_MOVE_SYNTAX 0 36 #define VALID_MOVE_SYNTAX 0
37 #define INVALID_MOVE_SYNTAX 1 37 #define INVALID_MOVE_SYNTAX 1
38 #define INVALID_POSITION 2 38 #define INVALID_POSITION 2
39 #define AMBIGUOUS_MOVE 3 39 #define AMBIGUOUS_MOVE 3
40 #define NEED_PROMOTION 4 40 #define NEED_PROMOTION 4
41 #define PIECE_PINNED 5
42 #define KING_IN_CHECK 6
41 43
42 44
43 #define PIECE_MASK 0x0F 45 #define PIECE_MASK 0x0F
44 #define COLOR_MASK 0x30 46 #define COLOR_MASK 0x30
45 #define ENPASSANT_THREAT 0x40 47 #define ENPASSANT_THREAT 0x40
165 * 167 *
166 * @param gamestate the current game state 168 * @param gamestate the current game state
167 * @param row row of the field to check 169 * @param row row of the field to check
168 * @param file file of the field to check 170 * @param file file of the field to check
169 * @param color the color of the piece that should threaten the field 171 * @param color the color of the piece that should threaten the field
170 * @param threats the array where to store the threats (should be able to the 172 * @param threats the array where to store the threats (should be able to hold
171 * rare maximum of 16 elements) 173 * the rare maximum of 16 elements)
172 * @param threatcount a pointer to an uint8_t where to store the amount of threats 174 * @param threatcount a pointer to an uint8_t where the count of threats is
175 * stored
173 * @return TRUE, if any piece of the specified color threatens the specified 176 * @return TRUE, if any piece of the specified color threatens the specified
174 * field (i.e. could capture an opponent piece) 177 * field (i.e. could capture an opponent piece)
175 */ 178 */
176 _Bool get_threats(GameState *gamestate, uint8_t row, uint8_t file, 179 _Bool get_threats(GameState *gamestate, uint8_t row, uint8_t file,
177 uint8_t color, Move* threats, uint8_t* threatcount); 180 uint8_t color, Move* threats, uint8_t* threatcount);
185 * 188 *
186 * @param gamestate the current game state 189 * @param gamestate the current game state
187 * @param row row of the field to check 190 * @param row row of the field to check
188 * @param file file of the field to check 191 * @param file file of the field to check
189 * @param color the color of the piece that should threaten the field 192 * @param color the color of the piece that should threaten the field
190 * @param threats the array where to store the threats (should be able to the 193 * @param threats the array where to store the threats (should be able to hold
191 * rare maximum of 16 elements) 194 * the rare maximum of 16 elements)
192 * @param threatcount a pointer to an uint8_t where to store the amount of threats 195 * @param threatcount a pointer to an uint8_t where the count of threats is
196 * stored
193 * @return TRUE, if any piece of the specified color threatens the specified 197 * @return TRUE, if any piece of the specified color threatens the specified
194 * field (i.e. could capture an opponent piece) 198 * field (i.e. could capture an opponent piece)
195 */ 199 */
196 _Bool get_real_threats(GameState *gamestate, uint8_t row, uint8_t file, 200 _Bool get_real_threats(GameState *gamestate, uint8_t row, uint8_t file,
197 uint8_t color, Move* threats, uint8_t* threatcount); 201 uint8_t color, Move* threats, uint8_t* threatcount);
240 */ 244 */
241 _Bool is_protected(GameState *gamestate, uint8_t row, uint8_t file, 245 _Bool is_protected(GameState *gamestate, uint8_t row, uint8_t file,
242 uint8_t color); 246 uint8_t color);
243 247
244 /** 248 /**
249 * Checks, if the specified move cannot be performed, because the piece is
250 * either pinned or cannot remove the check.
251 *
252 * Note: in chess a piece is pinned, when it can't be moved because the move
253 * would result in a check position. But this function <u>also</u> returns true,
254 * if the king is already in check position and the specified move does not
255 * protect the king.
256 *
257 * @param gamestate the current game state
258 * @param move the move to check
259 * @return TRUE, if the move cannot be performed because the king would be in
260 * check after the move
261 */
262 _Bool is_pinned(GameState *gamestate, Move *move);
263
264 /**
245 * Evaluates a move syntactically and stores the move data in the specified 265 * Evaluates a move syntactically and stores the move data in the specified
246 * object. 266 * object.
247 * 267 *
248 * @param gamestate the current game state 268 * @param gamestate the current game state
249 * @param mstr the input string to parse 269 * @param mstr the input string to parse

mercurial