src/chess/rules.h

changeset 224
93e0e89496fe
parent 220
04da225a5677
--- a/src/chess/rules.h	Tue Sep 08 13:55:48 2026 +0200
+++ b/src/chess/rules.h	Tue Sep 08 14:34:48 2026 +0200
@@ -49,7 +49,11 @@
 #define INVALID_CHECKMATE     11
 #define RULES_VIOLATED        32
 
-#if __STDC_VERSION__ < 202310L
+#ifdef __cplusplus
+extern "C" {
+#define enum_byte(name) enum e##name : uint8_t
+#define typedef_enum_byte(name) typedef enum e##name name
+#elif __STDC_VERSION__ < 202310L
 /* since #warning is also a C23 feature, the only hope is this: */
 #pragma GCC warning "Type safety for enums is only available since C23"
 #define enum_byte(name) enum e##name
@@ -82,6 +86,7 @@
 #define KING   0x06u
 
 enum_byte(Piece) {
+    NOPIECE = 0,
     WPAWN   = WHITE|PAWN,
     WROOK   = WHITE|ROOK,
     WKNIGHT = WHITE|KNIGHT,
@@ -203,8 +208,8 @@
 static inline bool isfile(char file) {return file >= 'a' && file <= 'h';}
 static inline bool isrank(char rank) {return rank >= '1' && rank <= '8';}
 
-static inline Rank rankidx(char rank) {return rank-'1';}
-static inline File fileidx(char file) {return file-'a';}
+static inline Rank rankidx(char rank) {return (Rank)(rank-'1');}
+static inline File fileidx(char file) {return (File)(file-'a');}
 
 static inline char rankchr(Rank rank) {return (char)rank+'1';}
 static inline char filechr(File file) {return (char)file+'a';}
@@ -348,7 +353,7 @@
  * @param rank the rank
  */
 static inline void piece_remove(GameState *gamestate, File file, Rank rank) {
-    piece_set(gamestate, file, rank, 0);
+    piece_set(gamestate, file, rank, NOPIECE);
 }
 
 typedef size_t(*moves_generator_func)(const GameState *gamestate,
@@ -717,5 +722,9 @@
  */
 bool check_no_material(const GameState *gamestate);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif	/* RULES_H */
 

mercurial