summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgrisBRC <[email protected]>2024-07-15 15:57:01 +0530
committerIgrisBRC <[email protected]>2024-07-15 15:57:01 +0530
commit463b7b6e330d9a30bdaf4e770501c5b7bd750b1c (patch)
tree8bb77040db36f893336141573b18c11130245d88
parent5baa0899d56c7e9b0100a87158dfa2eb870be4f0 (diff)
added pawn capture move
-rw-r--r--public/move.js21
1 files changed, 18 insertions, 3 deletions
diff --git a/public/move.js b/public/move.js
index 5dc49af..f7d8d4c 100644
--- a/public/move.js
+++ b/public/move.js
@@ -12,7 +12,7 @@ let board = [
let to_move = true //white to move
//console.log(board[7][1])
-//console.log(move(board, 3, 1, to_move))
+//console.log(move(board, 4, 4, to_move))
function move(board, y, x, to_move) {
if (to_move ^ board[y][x] > 0) {
@@ -57,7 +57,6 @@ function pawn_move(board, y, x) {
moves.push([y - 1, x])
}
- return moves
} else {
if (y == 1) {
if (board[y + 1][x] == 0) {
@@ -72,9 +71,25 @@ function pawn_move(board, y, x) {
} else if (!color && y != 7 && board[y + 1][x] == 0) {
moves.push([y + 1, x])
}
+ }
- return moves
+ if (color) {
+ if (x - 1 >= 0 && board[y - 1][x - 1] < 0 && y - 1 >= 0) {
+ moves.push([y - 1, x - 1])
+ }
+ if (x + 1 <= 7 && board[y - 1][x + 1] < 0 && y - 1 >= 0) {
+ moves.push([y - 1, x + 1])
+ }
+ } else {
+ if (x - 1 >= 0 && board[y + 1][x - 1] > 0 && y + 1 <= 7) {
+ moves.push([y + 1, x - 1])
+ }
+ if (x + 1 <= 7 && board[y + 1][x + 1] > 0 && y + 1 <= 7) {
+ moves.push([y + 1, x + 1])
+ }
}
+
+ return moves
}
function king_move(board, y, x) {