diff options
Diffstat (limited to 'src/grossmeister/ttable.rs')
-rw-r--r-- | src/grossmeister/ttable.rs | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/src/grossmeister/ttable.rs b/src/grossmeister/ttable.rs index b40bac1..162e4f5 100644 --- a/src/grossmeister/ttable.rs +++ b/src/grossmeister/ttable.rs @@ -33,7 +33,7 @@ struct TranspositionTable { impl Default for TranspositionTable { fn default() -> Self { Self { - table: vec![None; TTABLE_SIZE as usize] + table: vec![None; TTABLE_SIZE as usize], } } } @@ -46,13 +46,9 @@ impl TranspositionTable { /// This operation is safe from collisions since it compares the *full* hash /// TODO: only compare the other half of the hash fn get(&self, hash: u64) -> Option<&TranspositionTableItem> { - self.table[(hash % TTABLE_SIZE) as usize].as_ref().and_then(|item| { - if item.hash == hash { - Some(item) - } else { - None - } - }) + self.table[(hash % TTABLE_SIZE) as usize] + .as_ref() + .and_then(|item| if item.hash == hash { Some(item) } else { None }) } fn len(&self) -> usize { @@ -72,33 +68,43 @@ pub struct MasterTable { impl Grossmeister { pub fn transposition(&self) -> Option<&TranspositionTableItem> { - self.transposition_table.depth_preferred.get(self.board.hash) + self.transposition_table + .depth_preferred + .get(self.board.hash) .or(self.transposition_table.always_replace.get(self.board.hash)) } pub fn store_transposition(&mut self, transposition: TranspositionTableItem) { - self.transposition_table.always_replace.set(self.board.hash, transposition); - - if match self.transposition_table.depth_preferred.get(self.board.hash) { + self.transposition_table + .always_replace + .set(self.board.hash, transposition); + + if match self + .transposition_table + .depth_preferred + .get(self.board.hash) + { Some(existing_transposition) => transposition.depth >= existing_transposition.depth, - None => true + None => true, } { - self.transposition_table.depth_preferred.set(self.board.hash, transposition) + self.transposition_table + .depth_preferred + .set(self.board.hash, transposition) } // Store PV/Cut nodes in PV table // Note: Cut nodes are probably only relevant in close-to-mate situations if match transposition.node_type { NodeType::PV => true, // Always replace PV nodes - NodeType::Cut => { - match self.transposition_table.pv.get(self.board.hash) { - Some(existing_transposition) => existing_transposition.node_type != NodeType::PV, - None => true, - } - } + NodeType::Cut => match self.transposition_table.pv.get(self.board.hash) { + Some(existing_transposition) => existing_transposition.node_type != NodeType::PV, + None => true, + }, _ => false, } { - self.transposition_table.pv.set(self.board.hash, transposition) + self.transposition_table + .pv + .set(self.board.hash, transposition) } } @@ -108,7 +114,8 @@ impl Grossmeister { } pub fn table_full(&self) -> u64 { - let total_entries = self.transposition_table.always_replace.len() + self.transposition_table.depth_preferred.len(); + let total_entries = self.transposition_table.always_replace.len() + + self.transposition_table.depth_preferred.len(); let total_size = TTABLE_SIZE * 2; (1000.0 * (total_entries as f64 / total_size as f64)) as u64 } |