src/chess/rules.h

changeset 80
b980a7192b5a
parent 78
ceb9197b3c6d
equal deleted inserted replaced
79:ffd452cf05ff 80:b980a7192b5a
31 #define RULES_H 31 #define RULES_H
32 32
33 #include "game-info.h" 33 #include "game-info.h"
34 34
35 #include <stdint.h> 35 #include <stdint.h>
36 #include <stdbool.h>
36 37
37 #define VALID_MOVE_SYNTAX 0 38 #define VALID_MOVE_SYNTAX 0
38 #define VALID_MOVE_SEMANTICS 0 /* use same code for a success */ 39 #define VALID_MOVE_SEMANTICS 0 /* use same code for a success */
39 #define INVALID_MOVE_SYNTAX 1 40 #define INVALID_MOVE_SYNTAX 1
40 #define INVALID_POSITION 2 41 #define INVALID_POSITION 2
112 * @param color the color of the piece that should threaten the field 113 * @param color the color of the piece that should threaten the field
113 * @param threats the array where to store the threats (should be able to hold 114 * @param threats the array where to store the threats (should be able to hold
114 * the rare maximum of 16 elements) 115 * the rare maximum of 16 elements)
115 * @param threatcount a pointer to an uint8_t where the count of threats is 116 * @param threatcount a pointer to an uint8_t where the count of threats is
116 * stored 117 * stored
117 * @return TRUE, if any piece of the specified color threatens the specified 118 * @return true, if any piece of the specified color threatens the specified
118 * field (i.e. could capture an opponent piece) 119 * field (i.e. could capture an opponent piece)
119 */ 120 */
120 _Bool get_threats(GameState *gamestate, uint8_t row, uint8_t file, 121 bool get_threats(GameState *gamestate, uint8_t row, uint8_t file,
121 uint8_t color, Move* threats, uint8_t* threatcount); 122 uint8_t color, Move* threats, uint8_t* threatcount);
122 123
123 /** 124 /**
124 * Checks, if a specified field is covered by a piece of a certain color AND 125 * Checks, if a specified field is covered by a piece of a certain color AND
125 * if this piece is not pinned and therefore able to perform the move. 126 * if this piece is not pinned and therefore able to perform the move.
133 * @param color the color of the piece that should threaten the field 134 * @param color the color of the piece that should threaten the field
134 * @param threats the array where to store the threats (should be able to hold 135 * @param threats the array where to store the threats (should be able to hold
135 * the rare maximum of 16 elements) 136 * the rare maximum of 16 elements)
136 * @param threatcount a pointer to an uint8_t where the count of threats is 137 * @param threatcount a pointer to an uint8_t where the count of threats is
137 * stored 138 * stored
138 * @return TRUE, if any piece of the specified color threatens the specified 139 * @return true, if any piece of the specified color threatens the specified
139 * field (i.e. could capture an opponent piece) 140 * field (i.e. could capture an opponent piece)
140 */ 141 */
141 _Bool get_real_threats(GameState *gamestate, uint8_t row, uint8_t file, 142 bool get_real_threats(GameState *gamestate, uint8_t row, uint8_t file,
142 uint8_t color, Move* threats, uint8_t* threatcount); 143 uint8_t color, Move* threats, uint8_t* threatcount);
143 144
144 /** 145 /**
145 * 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.
146 * 147 *
147 * @param gamestate the current game state 148 * @param gamestate the current game state
148 * @param row row of the field to check 149 * @param row row of the field to check
149 * @param file file of the field to check 150 * @param file file of the field to check
150 * @param color the color of the piece that should cover the field 151 * @param color the color of the piece that should cover the field
151 * @return TRUE, if any piece of the specified color threatens the specified 152 * @return true, if any piece of the specified color threatens the specified
152 * field 153 * field
153 */ 154 */
154 #define is_covered(gamestate, row, file, color) \ 155 #define is_covered(gamestate, row, file, color) \
155 get_threats(gamestate, row, file, color, NULL, NULL) 156 get_threats(gamestate, row, file, color, NULL, NULL)
156 157
162 * 163 *
163 * @param gamestate the current game state 164 * @param gamestate the current game state
164 * @param row row of the field to check 165 * @param row row of the field to check
165 * @param file file of the field to check 166 * @param file file of the field to check
166 * @param color the color of the piece that should cover the field 167 * @param color the color of the piece that should cover the field
167 * @return TRUE, if any piece of the specified color threatens the specified 168 * @return true, if any piece of the specified color threatens the specified
168 * field and could capture an opponent piece 169 * field and could capture an opponent piece
169 */ 170 */
170 #define is_attacked(gamestate, row, file, color) \ 171 #define is_attacked(gamestate, row, file, color) \
171 get_real_threats(gamestate, row, file, color, NULL, NULL) 172 get_real_threats(gamestate, row, file, color, NULL, NULL)
172 173
178 * 179 *
179 * @param gamestate the current game state 180 * @param gamestate the current game state
180 * @param row row of the field to check 181 * @param row row of the field to check
181 * @param file file of the field to check 182 * @param file file of the field to check
182 * @param color the color of the piece that should cover the field 183 * @param color the color of the piece that should cover the field
183 * @return TRUE, if any piece (excluding the king) of the specified color 184 * @return true, if any piece (excluding the king) of the specified color
184 * threatens the specified field and could capture an opponent piece 185 * threatens the specified field and could capture an opponent piece
185 */ 186 */
186 _Bool is_protected(GameState *gamestate, uint8_t row, uint8_t file, 187 bool is_protected(GameState *gamestate, uint8_t row, uint8_t file,
187 uint8_t color); 188 uint8_t color);
188 189
189 /** 190 /**
190 * Checks, if the specified move cannot be performed, because the piece is 191 * Checks, if the specified move cannot be performed, because the piece is
191 * either pinned or cannot remove the check. 192 * either pinned or cannot remove the check.
195 * if the king is already in check position and the specified move does not 196 * if the king is already in check position and the specified move does not
196 * protect the king. 197 * protect the king.
197 * 198 *
198 * @param gamestate the current game state 199 * @param gamestate the current game state
199 * @param move the move to check 200 * @param move the move to check
200 * @return TRUE, if the move cannot be performed because the king would be in 201 * @return true, if the move cannot be performed because the king would be in
201 * check after the move 202 * check after the move
202 */ 203 */
203 _Bool is_pinned(GameState *gamestate, Move *move); 204 bool is_pinned(GameState *gamestate, Move *move);
204 205
205 /** 206 /**
206 * Evaluates a move syntactically and stores the move data in the specified 207 * Evaluates a move syntactically and stores the move data in the specified
207 * object. 208 * object.
208 * 209 *

mercurial