diff options
author | IgrisBRC <[email protected]> | 2024-07-12 16:16:24 +0530 |
---|---|---|
committer | GitHub <[email protected]> | 2024-07-12 16:16:24 +0530 |
commit | d865daddd654a3ed338e8a552771fc97aaa404e1 (patch) | |
tree | 299e14df2b673769adfee1e8f6c1104dd0413afe /app.js | |
parent | bb1ce7fe68a374f60b5cf85db318478f57beb0b9 (diff) | |
parent | b7af2f91f2115405155d244c09fbdd757b6de24c (diff) |
Merge branch 'main' into main
Diffstat (limited to 'app.js')
-rw-r--r-- | app.js | 70 |
1 files changed, 50 insertions, 20 deletions
@@ -1,20 +1,47 @@ - - let board = [ - [0, 1, 0, 0, 0, 0, 0, 0], - [1, 1, 0, 0, 0, 0, 0, 0], - [1, 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, 0, 0, 0, 0, 0, 0, 0], + [-6, -6, -6, -6, -6, -6, -6, -6], + [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], + [6, 6, 6, 6, 6, 6, 6, 6], [0, 0, 0, 0, 0, 0, 0, 0], ] -console.log(board.length) - -console.log(amelia_move(board, 0,0)) +//console.log(move(board, 1, 0)) +//move(board, 3, 3) + +function move(board, y, x) { + switch (board[y][x]) { + case 0: + return [] + case 1: + return king_move(board, y, x) + case -1: + return king_move(board, y, x) + case 2: + return amelia_move(board, y, x) + case -2: + return amelia_move(board, y, x) + case 3: + return rook_move(board, y, x) + case -3: + return rook_move(board, y, x) + case 4: + return bishop_move(board, y, x) + case -4: + return bishop_move(board, y, x) + case 5: + return knight_move(board, y, x) + case -5: + return knight_move(board, y, x) + case 6: + return pawn_move(board, y, x) + case -6: + return pawn_move(board, y, x) + } +} function pawn_move(board, y, x) { let moves = [] @@ -105,7 +132,8 @@ function rook_move(board, y, x) { for (let i = x + 1; i < board[1].length; i++) { if (board[y][i] != 0) { - if (color ^ board[y][i]) { + if (color ^ board[y][i] > 0) { + console.log(color ^ board[y][i]) moves.push([y, i]) break } @@ -116,7 +144,7 @@ function rook_move(board, y, x) { for (let i = x - 1; i >= 0; i--) { if (board[y][i] != 0) { - if (color ^ board[y][i]) { + if (color ^ board[y][i] > 0) { moves.push([y, i]) break } @@ -128,7 +156,7 @@ function rook_move(board, y, x) { for (let i = y + 1; i < board.length; i++) { if (board[i][x] != 0) { - if (color ^ board[i][x]) { + if (color ^ board[i][x] > 0) { moves.push([i, x]) break } @@ -139,7 +167,7 @@ function rook_move(board, y, x) { for (let i = y - 1; i >= 0; i--) { if (board[i][x] != 0) { - if (color ^ board[i][x]) { + if (color ^ board[i][x] > 0) { moves.push([i, x]) break } @@ -232,7 +260,8 @@ function amelia_move(board, y, x) { for (let i = x + 1; i < board[1].length; i++) { if (board[y][i] != 0) { - if (color ^ board[y][i]) { + if (color ^ board[y][i] > 0) { + console.log(color ^ board[y][i]) moves.push([y, i]) break } @@ -243,7 +272,7 @@ function amelia_move(board, y, x) { for (let i = x - 1; i >= 0; i--) { if (board[y][i] != 0) { - if (color ^ board[y][i]) { + if (color ^ board[y][i] > 0) { moves.push([y, i]) break } @@ -255,7 +284,7 @@ function amelia_move(board, y, x) { for (let i = y + 1; i < board.length; i++) { if (board[i][x] != 0) { - if (color ^ board[i][x]) { + if (color ^ board[i][x] > 0) { moves.push([i, x]) break } @@ -266,7 +295,7 @@ function amelia_move(board, y, x) { for (let i = y - 1; i >= 0; i--) { if (board[i][x] != 0) { - if (color ^ board[i][x]) { + if (color ^ board[i][x] > 0) { moves.push([i, x]) break } @@ -274,7 +303,6 @@ function amelia_move(board, y, x) { } moves.push([i, x]) } - let i = y + 1 let j = x + 1 @@ -344,3 +372,5 @@ function amelia_move(board, y, x) { } return moves } + +export {move} |