Do TT cutoffs before LMP, use TT move as starting best_move and readability changes
This commit is contained in:
@@ -10,11 +10,11 @@ pub struct TranspositionTable {
|
||||
|
||||
impl TranspositionTable {
|
||||
pub fn new() -> Self {
|
||||
Self::new_with_mb_size(TT_SIZE_IN_MB)
|
||||
Self::with_capacity(TT_SIZE_IN_MB)
|
||||
}
|
||||
|
||||
pub fn new_with_mb_size(size_in_mega_bytes: usize) -> Self {
|
||||
let size_in_bytes = size_in_mega_bytes * 1024 * 1024;
|
||||
pub fn with_capacity(size_in_mb: usize) -> Self {
|
||||
let size_in_bytes = size_in_mb * 1024 * 1024;
|
||||
let num_of_entries = size_in_bytes / std::mem::size_of::<TTEntry>();
|
||||
|
||||
Self {
|
||||
@@ -23,19 +23,19 @@ impl TranspositionTable {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lookup(&self, zobrist_hash: ZobristHash) -> Option<&TTEntry> {
|
||||
pub fn lookup(&self, zobrist_hash: ZobristHash) -> Option<TTEntry> {
|
||||
self.positions
|
||||
.get((zobrist_hash.0 % self.size) as usize)
|
||||
.and_then(|entry| entry.as_ref())
|
||||
.and_then(|entry| *entry)
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, tt_entry: TTEntry) {
|
||||
let idx = (tt_entry.hash.0 % self.size) as usize;
|
||||
self.positions[idx] = Some(tt_entry);
|
||||
pub fn insert(&mut self, entry: TTEntry) {
|
||||
let idx = (entry.hash.0 % self.size) as usize;
|
||||
self.positions[idx] = Some(entry);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct TTEntry {
|
||||
pub hash: ZobristHash,
|
||||
pub mv: Option<Move>,
|
||||
@@ -62,13 +62,21 @@ impl TTEntry {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum NodeType {
|
||||
Exact,
|
||||
LowerBound,
|
||||
UpperBound,
|
||||
}
|
||||
|
||||
impl NodeType {
|
||||
pub fn cutoff_eligible(self, score: i16, alpha: i16, beta: i16) -> bool {
|
||||
self == Self::Exact
|
||||
|| self == Self::LowerBound && score >= beta
|
||||
|| self == Self::UpperBound && score <= alpha
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{
|
||||
@@ -96,14 +104,14 @@ mod tests {
|
||||
dbg!(time_info.instant.elapsed());
|
||||
|
||||
let will_be_hash = from_fen(FEN_POSSIBLE).unwrap().hash;
|
||||
let tt_entry = game.tt.lookup(will_be_hash);
|
||||
let entry = game.tt.lookup(will_be_hash);
|
||||
|
||||
assert!(tt_entry.is_some());
|
||||
assert!(entry.is_some());
|
||||
|
||||
let wont_be_hash = from_fen(FEN_IMPOSSIBLE).unwrap().hash;
|
||||
let tt_entry = game.tt.lookup(wont_be_hash);
|
||||
let entry = game.tt.lookup(wont_be_hash);
|
||||
|
||||
assert!(tt_entry.is_none());
|
||||
assert!(entry.is_none());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user