diff --git a/panel/src/games/chess/ChessBoard.tsx b/panel/src/games/chess/ChessBoard.tsx index 7e0a5da..4d5ba7e 100644 --- a/panel/src/games/chess/ChessBoard.tsx +++ b/panel/src/games/chess/ChessBoard.tsx @@ -25,9 +25,12 @@ export function ChessBoard({ state, myPlayerId, isSpectator, onAction, players } return
Waiting for game to start...
; } - const myColor = chess.players.white === myPlayerId ? "white" : chess.players.black === myPlayerId ? "black" : null; + const isWhite = chess.players.white === myPlayerId; + const isBlack = chess.players.black === myPlayerId; + const isBothSides = isWhite && isBlack; // admin self-play + const myColor = isWhite ? "white" : isBlack ? "black" : null; const turn = game.turn() === "w" ? "white" : "black"; - const isMyTurn = myColor === turn && !isSpectator; + const isMyTurn = (isBothSides || myColor === turn) && !isSpectator; const boardOrientation = myColor ?? "white"; const opponentId = myColor === "white" ? chess.players.black : chess.players.white; @@ -50,7 +53,12 @@ export function ChessBoard({ state, myPlayerId, isSpectator, onAction, players } } } - const move = testGame.move({ from: sourceSquare, to: targetSquare }); + let move; + try { + move = testGame.move({ from: sourceSquare, to: targetSquare }); + } catch { + return false; + } if (!move) return false; onAction({ type: "move", from: sourceSquare, to: targetSquare }); @@ -70,6 +78,10 @@ export function ChessBoard({ state, myPlayerId, isSpectator, onAction, players } function isDraggablePiece({ piece }: { piece: string }): boolean { if (isSpectator || !isMyTurn) return false; + if (isBothSides) { + const pieceColor = piece[0] === "w" ? "white" : "black"; + return pieceColor === turn; + } const pieceColor = piece[0] === "w" ? "white" : "black"; return pieceColor === myColor; }