Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
feat: qsearch is now fail-soft. thanks ciekce
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyhammer committed Aug 20, 2024
1 parent 877b5d7 commit e8e4910
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions brogle/src/search/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,16 @@ impl<'a> Searcher<'a> {
if score > self.data.score {
self.data.score = score;

// Fail soft beta-cutoff.
// Could also `return Ok(self.data.score)` here, but we need to save bestmove to TT
if self.data.score >= beta {
break;
}

if self.data.score > alpha {
alpha = score;
self.data.bestmove = Some(mv);
}
}

// Opponent would never choose this branch, so we can prune
if alpha >= beta {
break;
// Fail soft beta-cutoff.
// Could also `return Ok(self.data.score)` here, but we need to save bestmove to TT
if self.data.score >= beta {
break;
}
}
}

Expand Down Expand Up @@ -199,23 +194,17 @@ impl<'a> Searcher<'a> {
if score > best {
best = score;

// Fail soft beta-cutoff.
// Could also `return Ok(best)` here, but we need to save bestmove to TT
if score >= beta {
break;
}

if score > alpha {
alpha = score;
// PV found
bestmove = mv;
}
}

// Beta cutoff (fail high)
if alpha >= beta {
// This was a "killer move"
break;
// Fail soft beta-cutoff.
// Could also `return Ok(best)` here, but we need to save bestmove to TT
if score >= beta {
break;
}
}
}

Expand Down Expand Up @@ -273,31 +262,27 @@ impl<'a> Searcher<'a> {
);
}

// If we've found a better move than our current best, update our result
if score > best {
best = score;

// Update alpha.
if score > alpha {
alpha = score;
// PV found
bestmove = mv;
}

// Opponent would never choose this branch, so we can prune (fail-high)
if alpha >= beta {
// Fail soft beta-cutoff.
// Could also `return Ok(best)` here, but we need to save bestmove to TT
if score >= beta {
break;
}
}

// Fail soft beta-cutoff;
if score >= beta {
break;
}
}

let flag = NodeType::new(best, original_alpha, beta);
self.save_to_ttable(game.key(), bestmove, best, 0, flag);
Ok(alpha)
Ok(best)
}

fn save_to_ttable(
Expand Down

0 comments on commit e8e4910

Please sign in to comment.