summaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-06-01 13:25:24 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-06-01 13:25:24 +0530
commitd2af19a9ee217f55de12a303d9d6283c76fe446b (patch)
tree299d98ee479b2d33bd6a580530a3309e0cd9f9e9 /assets
parent29822a5d0f63bf0c1b34da636ddf27ecf22ca3cb (diff)
fixed knight + fixed comms
Diffstat (limited to 'assets')
-rw-r--r--assets/board.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/assets/board.js b/assets/board.js
index 8c4fdfc..c8e2194 100644
--- a/assets/board.js
+++ b/assets/board.js
@@ -50,6 +50,11 @@ function checkForPiece(square, bitIndex, set = true) {
return null;
}
+function isYourTurn(piece) {
+ if (turn == "w") return piece < 6;
+ return piece >= 6;
+}
+
const selectedAction = trackBitboard;
window.onkeydown = (e) => {
@@ -90,6 +95,8 @@ function handleTransmission(data) {
let from = parseInt(moveData.slice(0, 2));
let to = parseInt(moveData.slice(2));
+ console.log(from, to, moveData);
+
if (validMoves[from] == undefined) validMoves[from] = []
validMoves[from].push(to);
}
@@ -153,8 +160,9 @@ window.onload = () => {
if (e.data == "END-TRANSMISSION") {
handleTransmission(data);
data = [];
+ } else {
+ data.push(e.data);
}
- data.push(e.data);
}
socket.onopen = () => {
console.log(old_fen);
@@ -202,6 +210,7 @@ window.onload = () => {
const sqr_id = parseInt(square.id.slice(7));
if (hoveringPiece == -1) {
if (piece == null) return;
+ if (!isYourTurn(piece)) return;
if (validMoves[bitIndex]) renderingMoves = validMoves[bitIndex];
setHoverpiece(piece);
pickedUpFrom = sqr_id;
@@ -216,13 +225,6 @@ window.onload = () => {
setHoverpiece(-1);
}
console.log(piece, hoveringPiece, square, renderingMoves);
- // if (
- // (hoveringPiece < 0 && piece == null) ||
- // (hoveringPiece >= 0 && piece != null)
- // ) return;
- // if (hoveringPiece < 0) {
- // } else {
- // }
updateRenderingMoves();
};
board.appendChild(square);