diff -r ce38ee9bc3af -r 189c7c77aaab src/chess/rules.c --- 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 #include +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;