src/chess/rules.c

changeset 219
24b866230dd4
parent 218
1e9751f8eb0d
child 220
04da225a5677
--- a/src/chess/rules.c	Fri Sep 04 13:49:48 2026 +0200
+++ b/src/chess/rules.c	Sat Sep 05 12:36:04 2026 +0200
@@ -45,7 +45,6 @@
 void gamestate_init(GameState *gamestate) {
     memset(gamestate, 0, sizeof(GameState));
 
-    // TODO: implement feature - game can be started from arbitrary position
     Board initboard = {
         {WROOK, WKNIGHT, WBISHOP, WQUEEN, WKING, WBISHOP, WKNIGHT, WROOK},
         {WPAWN, WPAWN,   WPAWN,   WPAWN,  WPAWN, WPAWN,   WPAWN,   WPAWN},
@@ -99,13 +98,9 @@
         simulation.fen_start = strdup(gamestate->fen_start);
     }
 
-    return simulation;
-}
+    // TODO: think about setting move_start to a reasonable value
 
-Color current_color(const GameState *gamestate) {
-    // TODO: better would be an API that returns the correct number
-    unsigned mc = gamestate->movecount + gamestate->move_start;
-    return (mc % 2 == 0) ? WHITE : BLACK;
+    return simulation;
 }
 
 static void calc_movetime(GameState *gamestate, Move *move) {
@@ -150,7 +145,7 @@
 }
 
 static bool check_stalemate(const GameState *gamestate) {
-    Color next_player = gamestate->movecount % 2 == 0 ? WHITE : BLACK;
+    Color next_player = current_color(gamestate);
 
     /* scan the board for pieces of the next player's color */
     Move moves[QUEEN_MOVES_MAX];
@@ -436,6 +431,7 @@
     gamestate_init(replay);
     memcpy(&replay->info, &gamestate->info, sizeof(GameInfo));
     replay->review = true;
+    // TODO: respect move_start offset
     if (move_number > gamestate->movecount) {
         move_number = gamestate->movecount;
     }
@@ -1262,6 +1258,7 @@
 }
 
 uint16_t remaining_movetime(const GameState *gamestate, Color color) {
+    // TODO: we probably need to add the move_start offset here...
     unsigned move_number = gamestate->movecount;
     if (color == BLACK) {
         move_number |= 1;
@@ -1272,6 +1269,7 @@
 }
 
 uint16_t remaining_movetime2(const GameState *gamestate, unsigned move_number) {
+    // TODO: ... and remove / consider the move_start offset here
     if (!gamestate->info.timecontrol) {
         return 0;
     }

mercurial