Skip to content

Commit

Permalink
relax eager check for too many pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Jul 4, 2024
1 parent bf9732d commit aa30d89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub enum SyzygyError {
/// Position has castling rights, but Syzygy tables do not contain
/// positions with castling rights.
Castling,
/// Position has too many pieces. Syzygy tables only support up to
/// 6 or 7 pieces.
/// Position has too many pieces, i.e., more pieces than any opened table.
/// Syzygy tables for standard chess support up to 7 pieces.
TooManyPieces,
/// Missing table.
MissingTable {
Expand Down
12 changes: 11 additions & 1 deletion src/tablebase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,14 @@ impl<S: Position + Clone + Syzygy> Tablebase<S> {
}

fn probe<'a>(&'a self, pos: &'a S) -> SyzygyResult<WdlEntry<'a, S>> {
if pos.board().occupied().count() > S::MAX_PIECES {
// Probing resolves captures, so sometimes we can obtain results
// for positions that have more pieces than the maximum amount of
// supported pieces. We artificially limit this to one additional
// level, to make sure search remains somewhat bounded.
if pos.board().occupied().count() > S::MAX_PIECES + 1 {
return Err(SyzygyError::TooManyPieces);
}

if pos.castles().any() {
return Err(SyzygyError::Castling);
}
Expand Down Expand Up @@ -629,6 +634,11 @@ impl<S: Position + Clone + Syzygy> Tablebase<S> {
return Ok(Wdl::Draw);
}

// More pieces than any opened table.
if pos.board().occupied().count() > self.max_pieces {
return Err(SyzygyError::TooManyPieces);
}

// Get raw WDL value from the appropriate table.
let key = Material::from_board(pos.board());
self.wdl_table(&key)
Expand Down

0 comments on commit aa30d89

Please sign in to comment.