summaryrefslogtreecommitdiff
path: root/public/board.js
diff options
context:
space:
mode:
authorIgrisBRC <[email protected]>2024-07-15 15:35:35 +0530
committerIgrisBRC <[email protected]>2024-07-15 15:35:35 +0530
commit26619e4353d551bb4e2a79059203a26c3f5f5647 (patch)
treefcf8e8e0a95536640a79f1086e982923a25d05a2 /public/board.js
parentce46cd25a35a11343f46a9caa0bf1af64600d941 (diff)
all the bugs so far have been fixed, black pawns move twice, and the highlighting does get cancelled when it should
Diffstat (limited to 'public/board.js')
-rw-r--r--public/board.js16
1 files changed, 5 insertions, 11 deletions
diff --git a/public/board.js b/public/board.js
index 94c72ac..0c07d80 100644
--- a/public/board.js
+++ b/public/board.js
@@ -13,17 +13,11 @@ for (let i = 0; i < squares.length; i++) {
function handle_highlight(id) {
return function() {
-
let moves = move(board, id.charCodeAt(0) - 48, id.charCodeAt(1) - 48, to_move)
- for (let i = 0; i < previously_highlighted_squares.length; i++) {
- //if (previously_highlighted_squares[i] == piece_square) {
- // continue
- //}
-
- let prev = document.getElementById(previously_highlighted_squares[i])
- prev.classList.remove('highlight')
- prev.onclick = null
+ for (let i = 0; i < squares.length; i++) {
+ squares[i].classList.remove('highlight')
+ squares[i].onclick = handle_highlight(squares[i].id)
}
for (let i = 0; i < moves.length; i++) {
@@ -39,9 +33,9 @@ function handle_highlight(id) {
function handle_move(from_id, to_id) {
return function() {
+
let table = { 1: 'K', 2: 'Q', 3: 'R', 4: 'B', 5: 'N', 6: 'p' }
- console.log(from_id.charCodeAt(0) - 48, from_id.charCodeAt(1) - 48, to_id.charCodeAt(0) - 48, to_id.charCodeAt(1) - 48)
make_move(board, from_id.charCodeAt(0) - 48, from_id.charCodeAt(1) - 48, to_id.charCodeAt(0) - 48, to_id.charCodeAt(1) - 48)
let from_element = document.getElementById(from_id)
@@ -58,7 +52,7 @@ function handle_move(from_id, to_id) {
for (let i = 0; i < previously_highlighted_squares.length; i++) {
let prev = document.getElementById(previously_highlighted_squares[i])
prev.classList.remove('highlight')
- prev.onclick = null
+ prev.onclick = handle_highlight
}
let piece = document.createElement('p')