summaryrefslogtreecommitdiff
path: root/chesshelpers.c
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2023-01-07 14:54:28 -0800
committerKai Stevenson <kai@kaistevenson.com>2023-01-07 14:54:57 -0800
commit441bf949eb45ff99963addb24ffbedfada510979 (patch)
treed4c9588515eb8f3b06eee8c8207d348613feb4e1 /chesshelpers.c
parent476c3bc7692442974c6d7533a59f7d26c5848fb5 (diff)
added en passant, version 1
Diffstat (limited to 'chesshelpers.c')
-rw-r--r--chesshelpers.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/chesshelpers.c b/chesshelpers.c
index 2e046c9..b64a0f4 100644
--- a/chesshelpers.c
+++ b/chesshelpers.c
@@ -17,6 +17,7 @@ board_t init_board(int** pieces) {
//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];
+ int captured = board.pieces[end.mx][end.my];
board.pieces[origin.mx][origin.my] = 0;
board.pieces[end.mx][end.my] = piece;
//white king moved
@@ -62,6 +63,11 @@ board_t make_move(board_t board, vector_t origin, vector_t end) {
//this is not an else if! lastPawnMove must be reset
if(piece == pawn || piece == pawn + 6) {
board.lastPawnMove = origin.mx;
+ //check if move was an en passant capture
+ if(captured == 0 && origin.mx != end.mx) {
+ //kill the enemy pawn
+ board.pieces[end.mx][origin.my] = 0;
+ }
}
else {
//en passant no longer possible
@@ -95,6 +101,15 @@ int is_color(board_t board, vector_t position, int color) {
return board.pieces[position.mx][position.my] >= 7;
}
}
+//returns true if a pawn that moved two squares would have been here if it moved one square
+int would_have_been_pawn(board_t board, vector_t position, int color) {
+ if(board.lastPawnMove == position.mx) {
+ if((position.my == 6 && color == 0) || (position.my == 2 && color == 1)) {
+ return 1;
+ }
+ }
+ return 0;
+}
//converts board coordinates into algebraic notation
char* get_readable_coords(vector_t position) {
char* output = malloc(3 * sizeof(char));