41 *lastmovecopy = *(simulation.lastmove); |
47 *lastmovecopy = *(simulation.lastmove); |
42 simulation.movelist = simulation.lastmove = lastmovecopy; |
48 simulation.movelist = simulation.lastmove = lastmovecopy; |
43 } |
49 } |
44 |
50 |
45 return simulation; |
51 return simulation; |
46 } |
|
47 |
|
48 void gamestate_init(GameState *gamestate) { |
|
49 memset(gamestate, 0, sizeof(GameState)); |
|
50 |
|
51 Board initboard = { |
|
52 {WROOK, WKNIGHT, WBISHOP, WQUEEN, WKING, WBISHOP, WKNIGHT, WROOK}, |
|
53 {WPAWN, WPAWN, WPAWN, WPAWN, WPAWN, WPAWN, WPAWN, WPAWN}, |
|
54 {0, 0, 0, 0, 0, 0, 0, 0}, |
|
55 {0, 0, 0, 0, 0, 0, 0, 0}, |
|
56 {0, 0, 0, 0, 0, 0, 0, 0}, |
|
57 {0, 0, 0, 0, 0, 0, 0, 0}, |
|
58 {BPAWN, BPAWN, BPAWN, BPAWN, BPAWN, BPAWN, BPAWN, BPAWN}, |
|
59 {BROOK, BKNIGHT, BBISHOP, BQUEEN, BKING, BBISHOP, BKNIGHT, BROOK} |
|
60 }; |
|
61 memcpy(gamestate->board, initboard, sizeof(Board)); |
|
62 } |
|
63 |
|
64 void gamestate_cleanup(GameState *gamestate) { |
|
65 MoveList *elem; |
|
66 elem = gamestate->movelist; |
|
67 while (elem) { |
|
68 MoveList *cur = elem; |
|
69 elem = elem->next; |
|
70 free(cur); |
|
71 }; |
|
72 } |
52 } |
73 |
53 |
74 /* MUST be called BETWEEN validating AND applying a move to work correctly */ |
54 /* MUST be called BETWEEN validating AND applying a move to work correctly */ |
75 static void format_move(GameState *gamestate, Move *move) { |
55 static void format_move(GameState *gamestate, Move *move) { |
76 char *string = &(move->string[0]); |
56 char *string = &(move->string[0]); |