diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-01-29 13:56:57 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-01-29 13:56:57 +0300 |
commit | dc120dc65742be2312a53afc887dd30a3ae96e04 (patch) | |
tree | e522a0713fa74449e73e48e6c724fa9b7e12ae7f /src/board | |
parent | e7159fad693b6db784ec5f93ed4b624465c1eb9c (diff) | |
download | chessnost-dc120dc65742be2312a53afc887dd30a3ae96e04.tar.gz |
feat: immediately return score of hash moves
Diffstat (limited to 'src/board')
-rw-r--r-- | src/board/engine.rs | 32 | ||||
-rw-r--r-- | src/board/ttable.rs | 2 |
2 files changed, 25 insertions, 9 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs index c43a722..da0f38b 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -217,11 +217,12 @@ impl Board { 0.0 } - pub fn hash_move(&self) -> Option<Move> { + /// Find current transposition in Transposition Table + pub fn transposition(&self) -> Option<TranspositionTableItem> { match self.transposition_table[(self.hash % TTABLE_SIZE) as usize] { Some(item) => { if item.hash == self.hash { - return Some(item.best_move) + return Some(item) } None } @@ -267,8 +268,8 @@ impl Board { } - match self.hash_move() { - Some(mov) => ordered_moves.insert(0, mov), + match self.transposition() { + Some(transposition) => ordered_moves.insert(0, transposition.mov), None => {}, } @@ -280,6 +281,21 @@ impl Board { let mut killer_moves = Vec::new(); let color = self.color(); + match self.transposition() { + Some(transposition) => { + if transposition.depth >= depth_left { + match transposition.node_type { + NodeType::PV => { // PV-nodes have exact score + principal_variation.push(transposition.mov); + return (transposition.score, principal_variation); + } + _ => {} // TODO: prune when out ouf bounds + } + } + } + None => {}, + } + let mut moves = self.generate_pseudolegal_moves(color); moves = self.order_moves(moves, parent_killers.to_vec()); @@ -319,7 +335,7 @@ impl Board { if score >= beta { self.transposition_table[(self.hash % TTABLE_SIZE) as usize] = Some(TranspositionTableItem { hash: self.hash, - best_move: mov, + mov, depth: depth_left, // TODO: should be actual depth searched node_type: NodeType::Cut, score, @@ -343,7 +359,7 @@ impl Board { self.transposition_table[(self.hash % TTABLE_SIZE) as usize] = Some(TranspositionTableItem { hash: self.hash, - best_move: mov, + mov, depth: depth_left, // TODO: should be actual depth searched node_type: NodeType::PV, score, @@ -351,7 +367,7 @@ impl Board { } else { self.transposition_table[(self.hash % TTABLE_SIZE) as usize] = Some(TranspositionTableItem { hash: self.hash, - best_move: mov, + mov, depth: depth_left, // TODO: should be actual depth searched node_type: NodeType::All, score, @@ -363,7 +379,7 @@ impl Board { // Could not finish in time, return what we have so far if Instant::now() > deadline { - return (alpha, principal_variation) + break; } } diff --git a/src/board/ttable.rs b/src/board/ttable.rs index 3a103da..9f9e0b0 100644 --- a/src/board/ttable.rs +++ b/src/board/ttable.rs @@ -15,7 +15,7 @@ pub enum NodeType { pub struct TranspositionTableItem { /// Zobrist hash of this position pub hash: u64, - pub best_move: Move, + pub mov: Move, pub depth: u8, pub score: f32, pub node_type: NodeType, |