src/chess/rules.c

changeset 129
189c7c77aaab
parent 122
e65d9b5e9324
child 130
3fc6b1d6cbe9
--- a/src/chess/rules.c	Tue May 26 15:29:00 2026 +0200
+++ b/src/chess/rules.c	Thu May 28 12:15:26 2026 +0200
@@ -40,6 +40,27 @@
 #include <stdlib.h>
 #include <sys/time.h>
 
+void gamestate_init(GameState *gamestate) {
+    memset(gamestate, 0, sizeof(GameState));
+
+    Board initboard = {
+        {WROOK, WKNIGHT, WBISHOP, WQUEEN, WKING, WBISHOP, WKNIGHT, WROOK},
+        {WPAWN, WPAWN,   WPAWN,   WPAWN,  WPAWN, WPAWN,   WPAWN,   WPAWN},
+        {0,     0,       0,       0,      0,     0,       0,       0},
+        {0,     0,       0,       0,      0,     0,       0,       0},
+        {0,     0,       0,       0,      0,     0,       0,       0},
+        {0,     0,       0,       0,      0,     0,       0,       0},
+        {BPAWN, BPAWN,   BPAWN,   BPAWN,  BPAWN, BPAWN,   BPAWN,   BPAWN},
+        {BROOK, BKNIGHT, BBISHOP, BQUEEN, BKING, BBISHOP, BKNIGHT, BROOK}
+    };
+    memcpy(gamestate->board, initboard, sizeof(Board));
+}
+
+void gamestate_cleanup(GameState *gamestate) {
+    free(gamestate->moves);
+    gamestate->movecount = gamestate->movecapacity = 0;
+}
+
 static GameState gamestate_copy_sim(GameState *gamestate) {
     GameState simulation = *gamestate;
 

mercurial