diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2022-12-07 15:20:01 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2022-12-07 15:20:01 -0800 |
| commit | c57fdac8fb91a29205bda4a8d8a6f91f4c1ec172 (patch) | |
| tree | 23013d55fac444edeb12f60591c30537a1b3173e /chesshelpers.c | |
| parent | f7a3feaacdab2f198c665ee11ff14a63ac84718e (diff) | |
fixed check detection. changed all board[8][8] arguments to int**
Diffstat (limited to 'chesshelpers.c')
| -rw-r--r-- | chesshelpers.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/chesshelpers.c b/chesshelpers.c index a0caadd..7a8178b 100644 --- a/chesshelpers.c +++ b/chesshelpers.c @@ -1,15 +1,16 @@ #include <stdlib.h> #include <string.h> +#include <stdio.h> #include "vector.h" #include "chesshelpers.h" int in_board(vector_t position) { return position.mx < 8 && position.mx >= 0 && position.my < 8 && position.my >= 0; } -int is_empty(int board[8][8], vector_t position) { +int is_empty(int** board, vector_t position) { return board[position.mx][position.my] == 0; } -int is_color(int board[8][8], vector_t position, int color) { +int is_color(int** board, vector_t position, int color) { if(color == 0) { return board[position.mx][position.my] >= 1 && board[position.mx][position.my] <= 6; } @@ -26,7 +27,7 @@ char* get_readable_coords(vector_t position) { return output; } //gets the proper algebraic notation for the move -char* get_move_name(int board[8][8], vector_t origin, vector_t end) { +char* get_move_name(int** board, vector_t origin, vector_t end) { int piece = board[origin.mx][origin.my]; if(piece > 6) { piece -= 6; @@ -59,11 +60,12 @@ char* get_move_name(int board[8][8], vector_t origin, vector_t end) { return output; } } -int** clone_board(int board[8][8]) { - int** newBoard = malloc(8 * 8 * sizeof(int)); +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[c][r] = board[c][r]; + newBoard[r][c] = board[r][c]; } } return newBoard; |
