Skip to content

Commit

Permalink
Add board.ForceSkipTurn() to skip a turn even when in check (use at o…
Browse files Browse the repository at this point in the history
…wn peril)
  • Loading branch information
SebLague committed Jul 26, 2023
1 parent 779c7f8 commit 0d6abe1
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions Chess-Challenge/src/API/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ public void UndoMove(Move move)
}

/// <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()
{
Expand All @@ -113,10 +114,25 @@ public bool TrySkipTurn()
return true;
}

/// <summary>
/// Undo a turn that was succesfully skipped with the TrySkipTurn method
/// </summary>
public void UndoSkipTurn()
/// <summary>
/// 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()
{
hasCachedMoves = false;
hasCachedCaptureMoves = false;
Expand Down

0 comments on commit 0d6abe1

Please sign in to comment.