From 441bf949eb45ff99963addb24ffbedfada510979 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sat, 7 Jan 2023 14:54:28 -0800 Subject: added en passant, version 1 --- chesshelpers.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'chesshelpers.c') 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)); -- cgit v1.3.1