Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass Button to skip turn #404

Open
Pain2821 opened this issue May 4, 2023 · 1 comment
Open

Pass Button to skip turn #404

Pain2821 opened this issue May 4, 2023 · 1 comment

Comments

@Pain2821
Copy link

Pain2821 commented May 4, 2023

Hey jeff I want to set a pass button in my forked lib please can you tell me the flow how I can pass turn like I was able to change this._turn but still in history turn is not changing.

Thank You.

@PhilBrockman
Copy link

I'm not sure if this would work for your use cases, but I found that I could switch the turn by conjuring a piece, having that
piece make a move, then removing the piece:

export function switchTurnsOnChessBoard(chessBoard: Chess) {
  const queen = {
    type: "q" as PieceSymbol,
    color: chessBoard.turn(),
  };
  while (true) {
    const squares = SQUARES.filter((square) => chessBoard.get(square) === null);
    const square = squares[Math.floor(Math.random() * squares.length)]!;
    chessBoard.put(queen, square);
    const queenMoves = chessBoard.moves({ square, verbose: true });
    if (queenMoves.length > 0) {
      const move = queenMoves[Math.floor(Math.random() * queenMoves.length)]!;
      chessBoard.move(move);
      chessBoard.remove(move.to);
      break;
    }
    chessBoard.remove(square);
  }
  return chessBoard;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants