summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgrisBRC <[email protected]>2024-07-12 12:13:55 +0530
committerIgrisBRC <[email protected]>2024-07-12 12:13:55 +0530
commitbfa0b985607ab325117b329801eb16b37aed683c (patch)
tree98d9e7fda1282fab40f3f2ccfe443d64809b0643
parent6cd48e7e8ff65720dd55fc37a7b17125cd29f768 (diff)
colorzid moves and fixed stuff
-rw-r--r--app.js117
-rw-r--r--game.js26
-rw-r--r--index.css6
-rw-r--r--index.html114
4 files changed, 184 insertions, 79 deletions
diff --git a/app.js b/app.js
index 65a5e7a..ebf0afc 100644
--- a/app.js
+++ b/app.js
@@ -2,7 +2,7 @@
let board = [
[0, 0, 0, 0, 0, 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],
@@ -11,36 +11,46 @@ let board = [
[0, 0, 0, 0, 0, 0, 0, 0],
]
-console.log(board.length)
-
-console.log(pawn_move(board, 1, 1))
+console.log(amelia_move(board, 7, 7))
function pawn_move(board, y, x) {
let moves = []
+ let color = board[y][x] > 0
- if (board[y][x] > 0) {
+ if (color) {
if (y == 6) {
- moves.push([y - 1, x])
- moves.push([y - 2, x])
- return moves
+ if (board[y - 1][x] == 0) {
+ moves.push([y - 1, x])
+ }
+ if (board[y - 2][x] == 0) {
+ moves.push([y - 2, x])
+ }
+ } else if (color && y != 0) {
+ if (board[y - 1][x] == 0) {
+ moves.push([y - 1, x])
+ }
}
- moves.push([y - 1, x])
return moves
} else {
if (y == 1) {
- moves.push([y + 1, x])
- moves.push([y + 2, x])
- return moves
+ if (board[y + 1][x] == 0) {
+ moves.push([y + 1, x])
+ }
+ if (board[y + 2][x] == 0) {
+ moves.push([y + 2, x])
+ }
+ } else if (color && y != 7) {
+ if (board[y + 1][x] == 0) {
+ moves.push([y + 1, x])
+ }
}
-
- moves.push([y + 1, x])
return moves
-
}
}
function king_move(board, y, x) {
+ let color = board[y][x] > 0
let moves = []
for (let i = y - 1; i <= y + 1; i += 1) {
@@ -48,7 +58,7 @@ function king_move(board, y, x) {
if ((i == y && j == x) || i < 0 || j < 0 || i >= board.length || j >= board[i].length) {
continue
}
- if (board[i][j] == 0) {
+ if (board[i][j] == 0 || (color ^ board[i][j] > 0)) {
moves.push([i, j])
}
}
@@ -58,6 +68,7 @@ function king_move(board, y, x) {
}
function knight_move(board, y, x) {
+ let color = board[y][x] > 0
let moves = []
let cand = [
@@ -76,8 +87,8 @@ function knight_move(board, y, x) {
continue
}
- if (board[i][j] == 0) {
- moves.push([i, j])
+ if (board[cand[k][0]][cand[k][1]] == 0 || (color ^ board[cand[k][0]][cand[k][1]] > 0)) {
+ moves.push([cand[k][0], cand[k][1]])
}
}
@@ -86,10 +97,15 @@ function knight_move(board, y, x) {
function rook_move(board, y, x) {
+ let color = board[y][x] > 0
let moves = []
for (let i = x + 1; i < board[1].length; i++) {
if (board[y][i] != 0) {
+ if (color ^ board[y][i]) {
+ moves.push([y, i])
+ break
+ }
break
}
moves.push([y, i])
@@ -97,6 +113,10 @@ function rook_move(board, y, x) {
for (let i = x - 1; i >= 0; i--) {
if (board[y][i] != 0) {
+ if (color ^ board[y][i]) {
+ moves.push([y, i])
+ break
+ }
break
}
moves.push([y, i])
@@ -105,6 +125,10 @@ 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]) {
+ moves.push([i, x])
+ break
+ }
break
}
moves.push([i, x])
@@ -112,6 +136,10 @@ function rook_move(board, y, x) {
for (let i = y - 1; i >= 0; i--) {
if (board[i][x] != 0) {
+ if (color ^ board[i][x]) {
+ moves.push([i, x])
+ break
+ }
break
}
moves.push([i, x])
@@ -121,6 +149,7 @@ function rook_move(board, y, x) {
}
function bishop_move(board, y, x) {
+ let color = board[y][x] > 0
let moves = []
let i = y + 1
@@ -128,6 +157,10 @@ function bishop_move(board, y, x) {
while (!(i < 0 || j < 0 || i >= board.length || j >= board[i].length)) {
if (board[i][j] != 0) {
+ if (color ^ board[i][j] > 0) {
+ moves.push([i, j])
+ break
+ }
break
}
@@ -141,6 +174,10 @@ function bishop_move(board, y, x) {
while (!(i < 0 || j < 0 || i >= board.length || j >= board[i].length)) {
if (board[i][j] != 0) {
+ if (color ^ board[i][j] > 0) {
+ moves.push([i, j])
+ break
+ }
break
}
@@ -154,6 +191,10 @@ function bishop_move(board, y, x) {
while (!(i < 0 || j < 0 || i >= board.length || j >= board[i].length)) {
if (board[i][j] != 0) {
+ if (color ^ board[i][j] > 0) {
+ moves.push([i, j])
+ break
+ }
break
}
@@ -167,6 +208,10 @@ function bishop_move(board, y, x) {
while (!(i < 0 || j < 0 || i >= board.length || j >= board[i].length)) {
if (board[i][j] != 0) {
+ if (color ^ board[i][j] > 0) {
+ moves.push([i, j])
+ break
+ }
break
}
@@ -179,10 +224,15 @@ function bishop_move(board, y, x) {
}
function amelia_move(board, y, x) {
+ let color = board[y][x] > 0
let moves = []
- for (let i = x + 1; i < board[0].length; i++) {
+ for (let i = x + 1; i < board[1].length; i++) {
if (board[y][i] != 0) {
+ if (color ^ board[y][i]) {
+ moves.push([y, i])
+ break
+ }
break
}
moves.push([y, i])
@@ -190,6 +240,10 @@ function amelia_move(board, y, x) {
for (let i = x - 1; i >= 0; i--) {
if (board[y][i] != 0) {
+ if (color ^ board[y][i]) {
+ moves.push([y, i])
+ break
+ }
break
}
moves.push([y, i])
@@ -198,6 +252,10 @@ 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]) {
+ moves.push([i, x])
+ break
+ }
break
}
moves.push([i, x])
@@ -205,6 +263,10 @@ function amelia_move(board, y, x) {
for (let i = y - 1; i >= 0; i--) {
if (board[i][x] != 0) {
+ if (color ^ board[i][x]) {
+ moves.push([i, x])
+ break
+ }
break
}
moves.push([i, x])
@@ -215,6 +277,10 @@ function amelia_move(board, y, x) {
while (!(i < 0 || j < 0 || i >= board.length || j >= board[i].length)) {
if (board[i][j] != 0) {
+ if (color ^ board[i][j] > 0) {
+ moves.push([i, j])
+ break
+ }
break
}
@@ -228,6 +294,10 @@ function amelia_move(board, y, x) {
while (!(i < 0 || j < 0 || i >= board.length || j >= board[i].length)) {
if (board[i][j] != 0) {
+ if (color ^ board[i][j] > 0) {
+ moves.push([i, j])
+ break
+ }
break
}
@@ -241,6 +311,10 @@ function amelia_move(board, y, x) {
while (!(i < 0 || j < 0 || i >= board.length || j >= board[i].length)) {
if (board[i][j] != 0) {
+ if (color ^ board[i][j] > 0) {
+ moves.push([i, j])
+ break
+ }
break
}
@@ -254,6 +328,10 @@ function amelia_move(board, y, x) {
while (!(i < 0 || j < 0 || i >= board.length || j >= board[i].length)) {
if (board[i][j] != 0) {
+ if (color ^ board[i][j] > 0) {
+ moves.push([i, j])
+ break
+ }
break
}
@@ -261,6 +339,5 @@ function amelia_move(board, y, x) {
i += 1
j -= 1
}
-
return moves
}
diff --git a/game.js b/game.js
new file mode 100644
index 0000000..7a670f1
--- /dev/null
+++ b/game.js
@@ -0,0 +1,26 @@
+const alphabet = 'abcdefgh'
+
+let board = [
+ [0, 0, 0, 0, 0, 0, 0, 0],
+ [-1, -1, -1, -1, -1, -1, -1, -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],
+ [1, 1, 1, 1, 1, 1, 1, 1],
+ [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
+ }
+ }
+}
diff --git a/index.css b/index.css
index 852deed..271e489 100644
--- a/index.css
+++ b/index.css
@@ -3,11 +3,13 @@
height: 100px;
width: 100px;
}
+
.black{
height: 100px;
width: 100px;
background-color: brown;
}
+
body{
height: 100vh;
width: 100vw;
@@ -15,11 +17,11 @@ body{
justify-content: center;
align-items: center;
}
+
.chess-board{
width: 800px;
height: 800px;
display: grid;
grid-template-columns:repeat(8,1fr);
grid-template-rows:repeat(8,1fr);
-
-} \ No newline at end of file
+}
diff --git a/index.html b/index.html
index ee597e8..1ea90b2 100644
--- a/index.html
+++ b/index.html
@@ -11,85 +11,85 @@
<div class="chess-board">
<div>
<div id="a8" class="1 white"></div>
- <div id="b8" class="2 black"></div>
- <div id="c8" class="3 white"></div>
- <div id="d8" class="4 black"></div>
- <div id="e8" class="5 white"></div>
- <div id="f8" class="6 black"></div>
- <div id="g8" class="7 white"></div>
- <div id="h8" class="8 black"></div>
+ <div id="a7" class="2 black"></div>
+ <div id="a6" class="3 white"></div>
+ <div id="a5" class="4 black"></div>
+ <div id="a4" class="5 white"></div>
+ <div id="a3" class="6 black"></div>
+ <div id="a2" class="7 white"></div>
+ <div id="a1" class="8 black"></div>
</div>
<div>
- <div id="a7" class="2 black"></div>
+ <div id="b8" class="2 black"></div>
<div id="b7" class="1 white"></div>
- <div id="c7" class="4 black"></div>
- <div id="d7" class="3 white"></div>
- <div id="e7" class="6 black"></div>
- <div id="f7" class="5 white"></div>
- <div id="g7" class="8 black"></div>
- <div id="h7" class="7 white"></div>
+ <div id="b6" class="4 black"></div>
+ <div id="b5" class="3 white"></div>
+ <div id="b4" class="6 black"></div>
+ <div id="b3" class="5 white"></div>
+ <div id="b2" class="8 black"></div>
+ <div id="b1" class="7 white"></div>
</div>
<div>
- <div id="a6" class="1 white"></div>
- <div id="b6" class="2 black"></div>
+ <div id="c8" class="1 white"></div>
+ <div id="c7" class="2 black"></div>
<div id="c6" class="3 white"></div>
- <div id="d6" class="4 black"></div>
- <div id="e6" class="5 white"></div>
- <div id="f6" class="6 black"></div>
- <div id="g6" class="7 white"></div>
- <div id="h6" class="8 black"></div>
+ <div id="c5" class="4 black"></div>
+ <div id="c4" class="5 white"></div>
+ <div id="c3" class="6 black"></div>
+ <div id="c2" class="7 white"></div>
+ <div id="c1" class="8 black"></div>
</div>
<div>
- <div id="a5" class="2 black"></div>
- <div id="b5" class="1 white"></div>
- <div id="c5" class="4 black"></div>
+ <div id="d8" class="2 black"></div>
+ <div id="d7" class="1 white"></div>
+ <div id="d6" class="4 black"></div>
<div id="d5" class="3 white"></div>
- <div id="e5" class="6 black"></div>
- <div id="f5" class="5 white"></div>
- <div id="g5" class="8 black"></div>
- <div id="h5" class="7 white"></div>
+ <div id="d4" class="6 black"></div>
+ <div id="d3" class="5 white"></div>
+ <div id="d2" class="8 black"></div>
+ <div id="d1" class="7 white"></div>
</div>
<div>
- <div id="a4" class="1 white"></div>
- <div id="b4" class="2 black"></div>
- <div id="c4" class="3 white"></div>
- <div id="d4" class="4 black"></div>
+ <div id="e8" class="1 white"></div>
+ <div id="e7" class="2 black"></div>
+ <div id="e6" class="3 white"></div>
+ <div id="e5" class="4 black"></div>
<div id="e4" class="5 white"></div>
- <div id="f4" class="6 black"></div>
- <div id="g4" class="7 white"></div>
- <div id="h4" class="8 black"></div>
+ <div id="e3" class="6 black"></div>
+ <div id="e2" class="7 white"></div>
+ <div id="e1" class="8 black"></div>
</div>
<div>
- <div id="a3" class="2 black"></div>
- <div id="b3" class="1 white"></div>
- <div id="c3" class="4 black"></div>
- <div id="d3" class="3 white"></div>
- <div id="e3" class="6 black"></div>
+ <div id="f8" class="2 black"></div>
+ <div id="f7" class="1 white"></div>
+ <div id="f6" class="4 black"></div>
+ <div id="f5" class="3 white"></div>
+ <div id="f4" class="6 black"></div>
<div id="f3" class="5 white"></div>
- <div id="g3" class="8 black"></div>
- <div id="h3" class="7 white"></div>
+ <div id="f2" class="8 black"></div>
+ <div id="f1" class="7 white"></div>
</div>
<div>
- <div id="a2" class="1 white"></div>
- <div id="b2" class="2 black"></div>
- <div id="c2" class="3 white"></div>
- <div id="d2" class="4 black"></div>
- <div id="e2" class="5 white"></div>
- <div id="f2" class="6 black"></div>
+ <div id="g8" class="1 white"></div>
+ <div id="g7" class="2 black"></div>
+ <div id="g6" class="3 white"></div>
+ <div id="g5" class="4 black"></div>
+ <div id="g4" class="5 white"></div>
+ <div id="g3" class="6 black"></div>
<div id="g2" class="7 white"></div>
- <div id="h2" class="8 black"></div>
+ <div id="g1" class="8 black"></div>
</div>
<div>
- <div id="a1" class="2 black"></div>
- <div id="b1" class="1 white"></div>
- <div id="c1" class="4 black"></div>
- <div id="d1" class="3 white"></div>
- <div id="e1" class="6 black"></div>
- <div id="f1" class="5 white"></div>
- <div id="g1" class="8 black"></div>
+ <div id="h8" class="2 black"></div>
+ <div id="h7" class="1 white"></div>
+ <div id="h6" class="4 black"></div>
+ <div id="h5" class="3 white"></div>
+ <div id="h4" class="6 black"></div>
+ <div id="h3" class="5 white"></div>
+ <div id="h2" class="8 black"></div>
<div id="h1" class="7 white"></div>
</div>
</div>
+ <script src="./game.js"></script>
</body>
-<script src=app.js></script>
</html>