From 44c45eb9c40e8e0cc4b598851a6577b8da26700d Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Thu, 8 Dec 2022 00:33:23 -0800 Subject: started migration to board state as struct --- chesshelpers.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'chesshelpers.c') 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; -} -- cgit v1.3.1