src/chess/rules.h

changeset 29
c6a1ad6cf749
parent 28
0c1371488d87
child 30
a285ee393860
equal deleted inserted replaced
28:0c1371488d87 29:c6a1ad6cf749
143 char getpiecechr(uint8_t piece); 143 char getpiecechr(uint8_t piece);
144 144
145 /** 145 /**
146 * Checks, if a specified field is covered by a piece of a certain color. 146 * Checks, if a specified field is covered by a piece of a certain color.
147 * 147 *
148 * Note: when the field is covered by multiple pieces, this function returns 148 * The out-parameters may both be NULL, but if any of them is set, the other
149 * the first piece it can find. 149 * must be set, too.
150 * 150 *
151 * @param gamestate the current game state 151 * @param gamestate the current game state
152 * @param row row of the field to check 152 * @param row row of the field to check
153 * @param file file 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 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 155 * @param threats the array where to store the threats (should be able to the
156 * the move that could be performed to capture the field should be stored 156 * rare maximum of 16 elements)
157 * @param threatcount a pointer to an uint8_t where to store the amount of threats
157 * @return TRUE, if any piece of the specified color threatens the specified 158 * @return TRUE, if any piece of the specified color threatens the specified
158 * field (i.e. could capture an opponent piece) 159 * field (i.e. could capture an opponent piece)
159 */ 160 */
160 _Bool get_any_threat_for(GameState *gamestate, uint8_t row, uint8_t file, 161 _Bool get_threats(GameState *gamestate, uint8_t row, uint8_t file,
161 uint8_t color, Move *threat); 162 uint8_t color, Move* threats, uint8_t* threatcount);
163
164 /**
165 * Checks, if a specified field is covered by a piece of a certain color AND
166 * if this piece is not pinned and therefore able to perform the move.
167 *
168 * The out-parameters may both be NULL, but if any of them is set, the other
169 * must be set, too.
170 *
171 * @param gamestate the current game state
172 * @param row row of the field to check
173 * @param file file of the field to check
174 * @param color the color of the piece that should threaten the field
175 * @param threats the array where to store the threats (should be able to the
176 * rare maximum of 16 elements)
177 * @param threatcount a pointer to an uint8_t where to store the amount of threats
178 * @return TRUE, if any piece of the specified color threatens the specified
179 * field (i.e. could capture an opponent piece)
180 */
181 _Bool get_real_threats(GameState *gamestate, uint8_t row, uint8_t file,
182 uint8_t color, Move* threats, uint8_t* threatcount);
162 183
163 /** 184 /**
164 * Checks, if a specified field is covered by a piece of a certain color. 185 * Checks, if a specified field is covered by a piece of a certain color.
165 * 186 *
166 * @param gamestate the current game state 187 * @param gamestate the current game state
167 * @param row row of the field to check 188 * @param row row of the field to check
168 * @param file file of the field to check 189 * @param file file of the field to check
169 * @param color the color of the piece that should cover the field 190 * @param color the color of the piece that should cover the field
170 * @return TRUE, if any piece of the specified color threatens the specified 191 * @return TRUE, if any piece of the specified color threatens the specified
171 * field (i.e. could capture an opponent piece) 192 * field
172 */ 193 */
173 #define is_covered(gamestate, row, file, color) \ 194 #define is_covered(gamestate, row, file, color) \
174 get_any_threat_for(gamestate, row, file, color, NULL) 195 get_threats(gamestate, row, file, color, NULL, NULL)
196
197 /**
198 * Checks, if a specified field is attacked by a piece of a certain color.
199 *
200 * I.e. the field is covered by a piece AND this piece is not pinned and
201 * therefore able to perform the move.
202 *
203 * @param gamestate the current game state
204 * @param row row of the field to check
205 * @param file file of the field to check
206 * @param color the color of the piece that should cover the field
207 * @return TRUE, if any piece of the specified color threatens the specified
208 * field and could capture an opponent piece
209 */
210 #define is_attacked(gamestate, row, file, color) \
211 get_threats(gamestate, row, file, color, NULL, NULL)
212
213 /**
214 * Checks, if a specified field is protected by a piece of a certain color.
215 *
216 * I.e. the field is covered by a piece that is NOT the king AND this piece is
217 * not pinned and therefore able to perform the move.
218 *
219 * @param gamestate the current game state
220 * @param row row of the field to check
221 * @param file file of the field to check
222 * @param color the color of the piece that should cover the field
223 * @return TRUE, if any piece (excluding the king) of the specified color
224 * threatens the specified field and could capture an opponent piece
225 */
226 _Bool is_protected(GameState *gamestate, uint8_t row, uint8_t file,
227 uint8_t color);
175 228
176 /** 229 /**
177 * Evaluates a move syntactically and stores the move data in the specified 230 * Evaluates a move syntactically and stores the move data in the specified
178 * object. 231 * object.
179 * 232 *

mercurial