aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-01-25 08:12:52 +0300
committereug-vs <eugene@eug-vs.xyz>2023-01-25 08:12:52 +0300
commit83d13da85bf089e74ebc7c1996e65e05eeabcd69 (patch)
tree20af78ab3c28dcb65a0722d2cbad2388f652087d
parente7f6024025169c6b0018132bb0b19bdfe91cb43f (diff)
downloadchessnost-83d13da85bf089e74ebc7c1996e65e05eeabcd69.tar.gz
feat: enable quiscence in negamax
-rw-r--r--src/board/engine.rs34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs
index 75a505e..c6ac512 100644
--- a/src/board/engine.rs
+++ b/src/board/engine.rs
@@ -122,8 +122,6 @@ impl Board {
}
pub fn negamax_search(&mut self, mut alpha: f32, beta: f32, depth_left: u8) -> (f32, Vec<Move>) {
- let transposition = self.transposition_table[(self.hash % TTABLE_SIZE) as usize];
-
let mut principal_variation = Vec::new();
let color = self.color();
@@ -135,20 +133,17 @@ impl Board {
a_eval.total_cmp(&b_eval)
});
- if transposition.is_some() {
- match transposition {
- Some(item) => {
- if item.node_type == NodeType::PV {
- // println!("Cache hit at depth {}: {:?}", depth_left, item);
- moves.insert(0, item.best_move);
- }
+ match self.transposition_table[(self.hash % TTABLE_SIZE) as usize] {
+ Some(item) => {
+ if item.node_type == NodeType::PV {
+ moves.insert(0, item.best_move);
}
- None => panic!("Unreachable"),
}
+ None => {},
}
if depth_left == 0 {
- return (self.evaluate(Some(moves.len() as f32)), principal_variation);
+ return (self.quiscence(alpha, beta), principal_variation);
}
for mov in moves {
@@ -190,7 +185,22 @@ impl Board {
pub fn quiscence(&mut self, mut alpha: f32, beta: f32) -> f32 {
let color = self.color();
- let moves = self.generate_pseudolegal_moves(color);
+ let mut moves = self.generate_pseudolegal_moves(color);
+
+ moves.sort_unstable_by(|a, b| {
+ let a_eval = self.eval_move(*a);
+ let b_eval = self.eval_move(*b);
+ a_eval.total_cmp(&b_eval)
+ });
+
+ match self.transposition_table[(self.hash % TTABLE_SIZE) as usize] {
+ Some(item) => {
+ if item.node_type == NodeType::PV {
+ moves.insert(0, item.best_move);
+ }
+ }
+ None => {},
+ }
let stand_pat = self.evaluate(Some(moves.len() as f32));