Add board.ForceSkipTurn() to skip a turn even when in check (use at own peril)

This commit is contained in:
Sebastian Lague 2023-07-26 10:54:56 +02:00
parent 779c7f8fb1
commit 0d6abe1ff0

View file

@ -97,9 +97,10 @@ namespace ChessChallenge.API
}
/// <summary>
/// Try skip the current turn
/// This will fail and return false if in check
/// Note: skipping a turn is not allowed in the game, but it can be used as a search technique
/// Try skip the current turn.
/// This will fail and return false if in check.
/// Note: skipping a turn is not allowed in the game, but it can be used as a search technique.
/// Skipped turns can be undone with UndoSkipTurn()
/// </summary>
public bool TrySkipTurn()
{
@ -114,7 +115,22 @@ namespace ChessChallenge.API
}
/// <summary>
/// Undo a turn that was succesfully skipped with the TrySkipTurn method
/// Forcibly skips the current turn.
/// Unlike TrySkipTurn(), this will work even when in check, which has some dangerous side-effects if done:
/// 1) Generating 'legal' moves will now include the illegal capture of the king.
/// 2) If the skipped turn is undone, the board will now incorrectly report that the position is not check.
/// Note: skipping a turn is not allowed in the game, but it can be used as a search technique.
/// Skipped turns can be undone with UndoSkipTurn()
/// </summary>
public void ForceSkipTurn()
{
hasCachedMoves = false;
hasCachedCaptureMoves = false;
board.MakeNullMove();
}
/// <summary>
/// Undo a turn that was succesfully skipped with TrySkipTurn() or ForceSkipTurn()
/// </summary>
public void UndoSkipTurn()
{