Expose insufficient material and repeated position functions
This commit is contained in:
parent
d18b6702f2
commit
188f6f8d3a
1 changed files with 24 additions and 11 deletions
|
@ -168,18 +168,31 @@ namespace ChessChallenge.API
|
||||||
public bool IsInCheckmate() => IsInCheck() && GetLegalMoves().Length == 0;
|
public bool IsInCheckmate() => IsInCheck() && GetLegalMoves().Length == 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test if the current position is a draw due stalemate,
|
/// Test if the current position is a draw due stalemate, repetition, insufficient material, or 50-move rule.
|
||||||
/// 3-fold repetition, insufficient material, or 50-move rule.
|
/// Note: this function will return true if the same position has occurred twice on the board (rather than 3 times,
|
||||||
|
/// which is when the game is actually drawn). This quirk is to help bots avoid repeating positions unnecessarily.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDraw()
|
public bool IsDraw()
|
||||||
{
|
{
|
||||||
return IsFiftyMoveDraw() || Arbiter.InsufficentMaterial(board) || IsInStalemate() || IsRepetition();
|
return IsFiftyMoveDraw() || IsInsufficientMaterial() || IsInStalemate() || IsRepeatedPosition();
|
||||||
|
|
||||||
bool IsInStalemate() => !IsInCheck() && GetLegalMoves().Length == 0;
|
bool IsInStalemate() => !IsInCheck() && GetLegalMoves().Length == 0;
|
||||||
bool IsFiftyMoveDraw() => board.currentGameState.fiftyMoveCounter >= 100;
|
bool IsFiftyMoveDraw() => board.currentGameState.fiftyMoveCounter >= 100;
|
||||||
bool IsRepetition() => repetitionHistory.Contains(board.ZobristKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test if the current position has occurred at least once before on the board.
|
||||||
|
/// This includes both positions in the actual game, and positions reached by
|
||||||
|
/// making moves while the bot is thinking.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsRepeatedPosition() => repetitionHistory.Contains(board.ZobristKey);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test if there are sufficient pieces remaining on the board to potentially deliver checkmate.
|
||||||
|
/// If not, the game is automatically a draw.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsInsufficientMaterial() => Arbiter.InsufficentMaterial(board);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Does the given player still have the right to castle kingside?
|
/// Does the given player still have the right to castle kingside?
|
||||||
/// Note that having the right to castle doesn't necessarily mean castling is legal right now
|
/// Note that having the right to castle doesn't necessarily mean castling is legal right now
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue