diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2022-12-08 00:33:23 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2022-12-08 00:33:23 -0800 |
| commit | 44c45eb9c40e8e0cc4b598851a6577b8da26700d (patch) | |
| tree | 22ef3ccc9c354739271226c81df470cc2d424add /chesshelpers.c | |
| parent | 26dff288134041d3245701b047be1d9a08c7c9d3 (diff) | |
started migration to board state as struct
Diffstat (limited to 'chesshelpers.c')
| -rw-r--r-- | chesshelpers.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/chesshelpers.c b/chesshelpers.c index 7a8178b..a471758 100644 --- a/chesshelpers.c +++ b/chesshelpers.c @@ -4,6 +4,20 @@ #include "vector.h" #include "chesshelpers.h" +board_t init_board(int** pieces) { + board_t board; + board.pieces = pieces; + board.blackKingHasMoved = 0; + board.whiteKingHasMoved = 0; + board.lastPawnMove = 0; + return board; +} +//function applies side effects to board values like king move state +board_t make_move(board_t board, vector_t origin, vector_t end) { + int piece = board.pieces[origin.mx][origin.my]; + board.pieces[origin.mx][origin.my] = 0; + board.pieces[end.mx][end.my] = piece; +} int in_board(vector_t position) { return position.mx < 8 && position.mx >= 0 && position.my < 8 && position.my >= 0; } @@ -60,13 +74,3 @@ char* get_move_name(int** board, vector_t origin, vector_t end) { return output; } } -int** clone_board(int** board) { - int** newBoard = malloc(8 * sizeof(int*)); - for(int r = 0; r < 8; r++) { - newBoard[r] = malloc(8 * sizeof(int)); - for(int c = 0; c < 8; c++) { - newBoard[r][c] = board[r][c]; - } - } - return newBoard; -} |
