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