diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-08-18 09:36:58 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-08-18 09:36:58 +0300 |
commit | ca2fc17834207b501b66d5c713889de029da27d6 (patch) | |
tree | a0a66e9aeefebc8e3d760c3ae1bce6619c4f8f23 /src | |
parent | 33de5e1bbcb57469b16b29bf0e207453ead9ea3e (diff) | |
download | c-chess-ca2fc17834207b501b66d5c713889de029da27d6.tar.gz |
feat: improve pawn movement
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 11 | ||||
-rw-r--r-- | src/pieces.h | 11 |
2 files changed, 18 insertions, 4 deletions
@@ -141,8 +141,15 @@ int validate_move(int move[2], int color, int* board) { legal_move = kingMoves; break; case PAWN: - if (piece & BLACK) legal_move = blackPawnMoves; - else legal_move = pawnMoves; + if (piece & BLACK) { + if (board[destination] != EMPTY) legal_move = blackPawnAttackMoves; + else if (origin >> 4 == 6) legal_move = newBlackPawnMoves; + else legal_move = blackPawnMoves; + } else { + if (board[destination] != EMPTY) legal_move = pawnAttackMoves; + else if (origin >> 4 == 1) legal_move = newPawnMoves; + else legal_move = pawnMoves; + } break; default: return -2; diff --git a/src/pieces.h b/src/pieces.h index 5689bb7..a88626a 100644 --- a/src/pieces.h +++ b/src/pieces.h @@ -31,8 +31,15 @@ int rookMoves[] = { 16, 1, -1, -16, 0 }; int queenMoves[] = { 17, 16, 15, 1, -1, -15, -16, -17, 0 }; int knightMoves[] = { 33, 31, 18, 14, -33, -31, -18, -14, 0 }; int kingMoves[] = { 17, 16, 15, 1, -1, -15, -16, -17, 0 }; -int pawnMoves[] = { 32, 17, 16, 15, 0 }; -int blackPawnMoves[] = { -32, -17, -16, -15, 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 }; #define FILE_MASK 0b1111 |