summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-08-20 15:50:26 +0300
committereug-vs <eugene@eug-vs.xyz>2022-08-20 15:50:26 +0300
commit9af05c593f57060d2532d80556ab1bc306660dc0 (patch)
tree1b4dcb71997fa8d43863a9f8022268b3aad7d42d
parent0725b563b85ba516b5dd7b104112ee0637ec57f5 (diff)
downloadc-chess-9af05c593f57060d2532d80556ab1bc306660dc0.tar.gz
fix: do not allow pawn jump through pieces
-rw-r--r--src/main.c11
-rw-r--r--src/pieces.h3
2 files changed, 8 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index f8f47e2..e3b043c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -146,11 +146,9 @@ int validate_move(Move move, int color, int* board) {
case PAWN:
if (piece & BLACK) {
if (board[move.destination] != EMPTY) legal_move = blackPawnAttackMoves;
- else if (move.origin >> 4 == 6) legal_move = newBlackPawnMoves;
else legal_move = blackPawnMoves;
} else {
if (board[move.destination] != EMPTY) legal_move = pawnAttackMoves;
- else if (move.origin >> 4 == 1) legal_move = newPawnMoves;
else legal_move = pawnMoves;
}
break;
@@ -168,7 +166,14 @@ int validate_move(Move move, int color, int* board) {
}
if (target_piece != EMPTY) break;
- if ((piece & NO_COLOR) == PAWN || (piece & NO_COLOR) == KNIGHT || (piece & NO_COLOR) == KING) break;
+ if (
+ (piece & NO_COLOR) == PAWN &&
+ !(
+ (move.origin >> 4 == 6 || move.origin >> 4 == 1) && // Pawn is new
+ abs(move.origin - square) == 16 // And this is only first move
+ )
+ ) break;
+ if ((piece & NO_COLOR) == KNIGHT || (piece & NO_COLOR) == KING) break;
}
legal_move++;
}
diff --git a/src/pieces.h b/src/pieces.h
index f975190..fd0abaf 100644
--- a/src/pieces.h
+++ b/src/pieces.h
@@ -35,9 +35,6 @@ int kingMoves[] = { 17, 16, 15, 1, -1, -15, -16, -17, 0 };
int pawnMoves[] = { 16, 0 };
int blackPawnMoves[] = { -16, 0 };
-int newPawnMoves[] = { 32, 16, 0 };
-int newBlackPawnMoves[] = { -32, -16, 0 };
-
int pawnAttackMoves[] = { 17, 15, 0 };
int blackPawnAttackMoves[] = { -17, -15, 0 };