| 47 #define MISSING_CHECKMATE 9 |
47 #define MISSING_CHECKMATE 9 |
| 48 #define INVALID_CHECK 10 |
48 #define INVALID_CHECK 10 |
| 49 #define INVALID_CHECKMATE 11 |
49 #define INVALID_CHECKMATE 11 |
| 50 #define RULES_VIOLATED 32 |
50 #define RULES_VIOLATED 32 |
| 51 |
51 |
| 52 #if __STDC_VERSION__ < 202310L |
52 #ifdef __cplusplus |
| |
53 extern "C" { |
| |
54 #define enum_byte(name) enum e##name : uint8_t |
| |
55 #define typedef_enum_byte(name) typedef enum e##name name |
| |
56 #elif __STDC_VERSION__ < 202310L |
| 53 /* since #warning is also a C23 feature, the only hope is this: */ |
57 /* since #warning is also a C23 feature, the only hope is this: */ |
| 54 #pragma GCC warning "Type safety for enums is only available since C23" |
58 #pragma GCC warning "Type safety for enums is only available since C23" |
| 55 #define enum_byte(name) enum e##name |
59 #define enum_byte(name) enum e##name |
| 56 #define typedef_enum_byte(name) typedef uint8_t name |
60 #define typedef_enum_byte(name) typedef uint8_t name |
| 57 #else |
61 #else |
| 201 static inline bool isidxr(uint8_t idx) {return idx==POS_UNSPECIFIED || idx<8;} |
206 static inline bool isidxr(uint8_t idx) {return idx==POS_UNSPECIFIED || idx<8;} |
| 202 |
207 |
| 203 static inline bool isfile(char file) {return file >= 'a' && file <= 'h';} |
208 static inline bool isfile(char file) {return file >= 'a' && file <= 'h';} |
| 204 static inline bool isrank(char rank) {return rank >= '1' && rank <= '8';} |
209 static inline bool isrank(char rank) {return rank >= '1' && rank <= '8';} |
| 205 |
210 |
| 206 static inline Rank rankidx(char rank) {return rank-'1';} |
211 static inline Rank rankidx(char rank) {return (Rank)(rank-'1');} |
| 207 static inline File fileidx(char file) {return file-'a';} |
212 static inline File fileidx(char file) {return (File)(file-'a');} |
| 208 |
213 |
| 209 static inline char rankchr(Rank rank) {return (char)rank+'1';} |
214 static inline char rankchr(Rank rank) {return (char)rank+'1';} |
| 210 static inline char filechr(File file) {return (char)file+'a';} |
215 static inline char filechr(File file) {return (char)file+'a';} |
| 211 |
216 |
| 212 |
217 |
| 346 * @param gamestate the current game state |
351 * @param gamestate the current game state |
| 347 * @param file the file |
352 * @param file the file |
| 348 * @param rank the rank |
353 * @param rank the rank |
| 349 */ |
354 */ |
| 350 static inline void piece_remove(GameState *gamestate, File file, Rank rank) { |
355 static inline void piece_remove(GameState *gamestate, File file, Rank rank) { |
| 351 piece_set(gamestate, file, rank, 0); |
356 piece_set(gamestate, file, rank, NOPIECE); |
| 352 } |
357 } |
| 353 |
358 |
| 354 typedef size_t(*moves_generator_func)(const GameState *gamestate, |
359 typedef size_t(*moves_generator_func)(const GameState *gamestate, |
| 355 Color c, File f, Rank r, Move *moves); |
360 Color c, File f, Rank r, Move *moves); |
| 356 |
361 |