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 | |
parent | bb1ce7fe68a374f60b5cf85db318478f57beb0b9 (diff) | |
parent | b7af2f91f2115405155d244c09fbdd757b6de24c (diff) |
Merge branch 'main' into main
-rw-r--r-- | app.js | 70 | ||||
-rw-r--r-- | game.js | 44 | ||||
-rw-r--r-- | index.html | 1 | ||||
-rw-r--r-- | package.json | 1 |
4 files changed, 80 insertions, 36 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} @@ -1,26 +1,38 @@ -const alphabet = 'abcdefgh' +import { move } from "./app.js" + +//const alphabet = 'abcdefgh' +//let squares = document.getElementsByClassName("square") let board = [ [0, 0, 0, 0, 0, 0, 0, 0], - [-1, -1, -1, -1, -1, -1, -1, -1], + [-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], - [1, 1, 1, 1, 1, 1, 1, 1], + [6, 6, 6, 6, 6, 6, 6, 6], [0, 0, 0, 0, 0, 0, 0, 0], ] -for (let i = 0; i < 8; i ++) { - for (let j = 0; j < 8; j ++) { - let square = document.getElementById(`${alphabet.charAt(j)}${i+1}`) - switch (board[i][j]) { - case 1: - square.append("p") - break - case -1: - square.append("p") - break - } - } -} +console.log(move(board, 1, 0)) + +//for (let i = 0; i < 8; i++) { +// for (let j = 0; j < 8; j++) { +// let square = document.getElementById(`${alphabet.charAt(j)}${i + 1}`) +// let piece = document.createElement("p") +// +// switch (board[i][j]) { +// case 1: +// piece.classList.add("wp") +// square.append(piece) +// piece.append("p") +// break +// case -1: +// piece.classList.add("bp") +// square.append(piece) +// piece.append("p") +// break +// } +// } +//} + @@ -10,6 +10,7 @@ <body> <div class="chess-board"> <div> + <div id="a8" class="box white"> <div class="top-corner">8</div> </div> diff --git a/package.json b/package.json index 3098cdc..15058b1 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "chess", "version": "1.0.0", "main": "index.js", + "type": "module", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, |