src/chess/rules.c

changeset 129
189c7c77aaab
parent 122
e65d9b5e9324
child 130
3fc6b1d6cbe9
equal deleted inserted replaced
128:ce38ee9bc3af 129:189c7c77aaab
37 37
38 #include <string.h> 38 #include <string.h>
39 #include <stdio.h> 39 #include <stdio.h>
40 #include <stdlib.h> 40 #include <stdlib.h>
41 #include <sys/time.h> 41 #include <sys/time.h>
42
43 void gamestate_init(GameState *gamestate) {
44 memset(gamestate, 0, sizeof(GameState));
45
46 Board initboard = {
47 {WROOK, WKNIGHT, WBISHOP, WQUEEN, WKING, WBISHOP, WKNIGHT, WROOK},
48 {WPAWN, WPAWN, WPAWN, WPAWN, WPAWN, WPAWN, WPAWN, WPAWN},
49 {0, 0, 0, 0, 0, 0, 0, 0},
50 {0, 0, 0, 0, 0, 0, 0, 0},
51 {0, 0, 0, 0, 0, 0, 0, 0},
52 {0, 0, 0, 0, 0, 0, 0, 0},
53 {BPAWN, BPAWN, BPAWN, BPAWN, BPAWN, BPAWN, BPAWN, BPAWN},
54 {BROOK, BKNIGHT, BBISHOP, BQUEEN, BKING, BBISHOP, BKNIGHT, BROOK}
55 };
56 memcpy(gamestate->board, initboard, sizeof(Board));
57 }
58
59 void gamestate_cleanup(GameState *gamestate) {
60 free(gamestate->moves);
61 gamestate->movecount = gamestate->movecapacity = 0;
62 }
42 63
43 static GameState gamestate_copy_sim(GameState *gamestate) { 64 static GameState gamestate_copy_sim(GameState *gamestate) {
44 GameState simulation = *gamestate; 65 GameState simulation = *gamestate;
45 66
46 // create a new move list for the simulation 67 // create a new move list for the simulation

mercurial