summaryrefslogtreecommitdiff
path: root/chesshelpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'chesshelpers.c')
-rw-r--r--chesshelpers.c24
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;
-}