Fix stalemate detection after generating capture moves in a position with no captures available
#418
This commit is contained in:
parent
bcd8cbb423
commit
1315551493
2 changed files with 21 additions and 4 deletions
|
@ -174,8 +174,12 @@ namespace ChessChallenge.API
|
|||
{
|
||||
bool includeQuietMoves = !capturesOnly;
|
||||
moveGen.GenerateMoves(ref moveList, board, includeQuietMoves);
|
||||
hasCachedMoveCount = true;
|
||||
cachedMoveCount = moveList.Length;
|
||||
|
||||
if (!capturesOnly)
|
||||
{
|
||||
hasCachedMoveCount = true;
|
||||
cachedMoveCount = moveList.Length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -368,6 +368,19 @@ namespace ChessChallenge.Application
|
|||
Assert(!boardAPI.IsDraw(), "Draw wrong");
|
||||
boardAPI.MakeMove(new API.Move("f5f7", boardAPI));
|
||||
Assert(boardAPI.IsDraw(), "Draw wrong");
|
||||
// Test stalemate bug when generating captures
|
||||
board.LoadPosition("8/8/3k4/8/8/3K4/4Q3/8 w - - 0 1");
|
||||
boardAPI = new API.Board(board);
|
||||
var captures = boardAPI.GetLegalMoves(capturesOnly: true);
|
||||
Assert(captures.Length == 0, "Wrong capture count");
|
||||
Assert(!boardAPI.IsInStalemate(), "Stalemate wrong");
|
||||
// Test stalemate bug when generating captures (non alloc)
|
||||
board.LoadPosition("8/8/3k4/8/8/3K4/4Q3/8 w - - 0 1");
|
||||
boardAPI = new API.Board(board);
|
||||
Span<API.Move> captureSpan = stackalloc API.Move[64];
|
||||
boardAPI.GetLegalMovesNonAlloc(ref captureSpan, capturesOnly: true);
|
||||
Assert(captureSpan.Length == 0, "Wrong capture count");
|
||||
Assert(!boardAPI.IsInStalemate(), "Stalemate wrong");
|
||||
|
||||
// Insufficient material
|
||||
board = new Chess.Board();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue