diff options
author | IgrisBRC <[email protected]> | 2024-07-11 15:44:11 +0530 |
---|---|---|
committer | IgrisBRC <[email protected]> | 2024-07-11 15:44:11 +0530 |
commit | 6cd48e7e8ff65720dd55fc37a7b17125cd29f768 (patch) | |
tree | 20b38673800731aff82fd515453ecdf99bc41eed | |
parent | 147f984e73ac93da92758a629c662e7e44080e4d (diff) |
added pawn move
-rw-r--r-- | app.js | 36 |
1 files changed, 28 insertions, 8 deletions
@@ -1,9 +1,11 @@ + + let board = [ [0, 0, 0, 0, 0, 0, 0, 0], - [0, 1, 0, 0, 0, 0, 0, 0], - [0, 0, 1, 1, 1, 0, 0, 0], - [0, 0, 1, 2, 1, 0, 0, 0], - [0, 0, 1, 1, 1, 0, 0, 0], + [0, -1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], @@ -11,10 +13,31 @@ let board = [ console.log(board.length) -console.log(amelia_move(board, 3, 3)) +console.log(pawn_move(board, 1, 1)) function pawn_move(board, y, x) { + let moves = [] + + if (board[y][x] > 0) { + if (y == 6) { + moves.push([y - 1, x]) + moves.push([y - 2, x]) + return moves + } + moves.push([y - 1, x]) + return moves + } else { + if (y == 1) { + moves.push([y + 1, x]) + moves.push([y + 2, x]) + return moves + } + + moves.push([y + 1, x]) + return moves + + } } function king_move(board, y, x) { @@ -241,6 +264,3 @@ function amelia_move(board, y, x) { return moves } - - - |