From a734e0af70a14dc8d635ab988c82e1a2e0b49836 Mon Sep 17 00:00:00 2001 From: IgrisBRC Date: Sun, 14 Jul 2024 07:47:23 +0530 Subject: fixed critical error in highlighting, the moves were mapped mirrored from the board --- public/app.js | 19 +++----- public/game.js | 10 +++-- public/index.css | 5 +++ public/index.html | 132 ++++++++++++++++++++++++++++-------------------------- 4 files changed, 86 insertions(+), 80 deletions(-) (limited to 'public') diff --git a/public/app.js b/public/app.js index bbb8d4b..a8db6b2 100644 --- a/public/app.js +++ b/public/app.js @@ -1,16 +1,15 @@ let board = [ [-3, -5, -4, -2, -1, -4, -5, -3], [-6, -6, -6, -6, -6, -6, -6, -6], + [0, 0, -5, 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, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [6, 6, 6, 6, 6, 6, 6, 6], [3, 5, 4, 2, 1, 4, 5, 3], ] - -//console.log(move(board, 1, 0)) +//console.log(move(board, 4, 3)) //move(board, 3, 3) function move(board, y, x) { @@ -45,10 +44,8 @@ function pawn_move(board, y, 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]) - } + } else if (color && y != 0 && board[y - 1][x] == 0) { + moves.push([y - 1, x]) } return moves @@ -60,10 +57,8 @@ function pawn_move(board, y, 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]) - } + } else if (color && y != 7 && board[y + 1][x] == 0) { + moves.push([y + 1, x]) } return moves } diff --git a/public/game.js b/public/game.js index 05ddc66..e5740de 100644 --- a/public/game.js +++ b/public/game.js @@ -3,7 +3,7 @@ const alphabet = 'abcdefgh' for (let i = 0; i < 8; i++) { for (let j = 0; j < 8; j++) { - let square = document.getElementById(`${alphabet.charAt(j)}${i + 1}`) + let square = document.getElementById(`${alphabet.charAt(j)}${8 - i}`) let piece = document.createElement('p') piece.classList.add('piece') @@ -73,9 +73,9 @@ for (let i = 0; i < 8; i++) { } } -let squares = document.getElementsByClassName('box') +let squares = document.getElementsByClassName('square') -let previously_highlighted_squares = ["dummy"] +let previously_highlighted_squares = ['dummy'] for (let i = 0; i < squares.length; i++) { @@ -87,15 +87,17 @@ for (let i = 0; i < squares.length; i++) { square.push(8 - id.charAt(1)) square.push(id.charAt(0).charCodeAt(0) - 97) + let moves = move(board, square[0], square[1]) for (let i = 0; i < previously_highlighted_squares.length; i++) { + //document.getElementById(previously_highlighted_squares[i]).style.backgroundColor = 'transparent' document.getElementById(previously_highlighted_squares[i]).classList.remove('highlight') } - for (let i = 0; i < moves.length; i++) { + //document.getElementById(`${alphabet[moves[i][1]]}${8 - moves[i][0]}`).style.backgroundColor = 'yellow' document.getElementById(`${alphabet[moves[i][1]]}${8 - moves[i][0]}`).classList.add('highlight') previously_highlighted_squares.push(`${alphabet[moves[i][1]]}${8 - moves[i][0]}`) } diff --git a/public/index.css b/public/index.css index 0b9d6da..7fa778a 100644 --- a/public/index.css +++ b/public/index.css @@ -21,6 +21,7 @@ .white{ background-color: #eaead2; + /*background-color: #4b7299; */ color: #4b7299; } @@ -55,3 +56,7 @@ body{ .highlight { background-color: yellow; } + +/*.wp {*/ +/* color: white;*/ +/*}*/ diff --git a/public/index.html b/public/index.html index 476efe5..20bda5a 100644 --- a/public/index.html +++ b/public/index.html @@ -8,116 +8,120 @@
+ + + +
-
+
8
-
+
7
-
+
6
-
+
5
-
+
4
-
+
3
-
+
2
-
+
1
a
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
b
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
c
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
d
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
e
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
f
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
g
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
h
-- cgit v1.2.3