summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgrisBRC <[email protected]>2024-07-12 16:16:24 +0530
committerGitHub <[email protected]>2024-07-12 16:16:24 +0530
commitd865daddd654a3ed338e8a552771fc97aaa404e1 (patch)
tree299e14df2b673769adfee1e8f6c1104dd0413afe
parentbb1ce7fe68a374f60b5cf85db318478f57beb0b9 (diff)
parentb7af2f91f2115405155d244c09fbdd757b6de24c (diff)
Merge branch 'main' into main
-rw-r--r--app.js70
-rw-r--r--game.js44
-rw-r--r--index.html1
-rw-r--r--package.json1
4 files changed, 80 insertions, 36 deletions
diff --git a/app.js b/app.js
index 8e41b32..f988614 100644
--- a/app.js
+++ b/app.js
@@ -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}
diff --git a/game.js b/game.js
index 7a670f1..73519bc 100644
--- a/game.js
+++ b/game.js
@@ -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
+// }
+// }
+//}
+
diff --git a/index.html b/index.html
index 8954901..0ccafc6 100644
--- a/index.html
+++ b/index.html
@@ -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"
},