src/chess/rules.h

changeset 224
93e0e89496fe
parent 220
04da225a5677
equal deleted inserted replaced
223:e2519b3dd5e7 224:93e0e89496fe
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
80 #define BISHOP 0x04u 84 #define BISHOP 0x04u
81 #define QUEEN 0x05u 85 #define QUEEN 0x05u
82 #define KING 0x06u 86 #define KING 0x06u
83 87
84 enum_byte(Piece) { 88 enum_byte(Piece) {
89 NOPIECE = 0,
85 WPAWN = WHITE|PAWN, 90 WPAWN = WHITE|PAWN,
86 WROOK = WHITE|ROOK, 91 WROOK = WHITE|ROOK,
87 WKNIGHT = WHITE|KNIGHT, 92 WKNIGHT = WHITE|KNIGHT,
88 WBISHOP = WHITE|BISHOP, 93 WBISHOP = WHITE|BISHOP,
89 WQUEEN = WHITE|QUEEN, 94 WQUEEN = WHITE|QUEEN,
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
715 * @param gamestate the current game state 720 * @param gamestate the current game state
716 * @return true if neither side can win due to insufficient material 721 * @return true if neither side can win due to insufficient material
717 */ 722 */
718 bool check_no_material(const GameState *gamestate); 723 bool check_no_material(const GameState *gamestate);
719 724
725 #ifdef __cplusplus
726 }
727 #endif
728
720 #endif /* RULES_H */ 729 #endif /* RULES_H */
721 730

mercurial