From 6cd48e7e8ff65720dd55fc37a7b17125cd29f768 Mon Sep 17 00:00:00 2001 From: IgrisBRC Date: Thu, 11 Jul 2024 15:44:11 +0530 Subject: added pawn move --- app.js | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index 53d2920..65a5e7a 100644 --- a/app.js +++ b/app.js @@ -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 } - - - -- cgit v1.2.3