diff options
Diffstat (limited to 'assets/board.js')
| -rw-r--r-- | assets/board.js | 18 |
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); |
