diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-02-21 17:49:51 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-02-23 14:01:03 +0300 |
commit | f60c573ba71207c18a28413e3940a4e21b07c73f (patch) | |
tree | 3e50e9ea6cd0129414db92cd50805ebeb65a4676 /src/grossmeister/ttable.rs | |
parent | 69f3c48fb99d96f3fbc4ab49f5fb6d1d8e90e270 (diff) | |
download | chessnost-f60c573ba71207c18a28413e3940a4e21b07c73f.tar.gz |
refactor: create grossmeister module
Diffstat (limited to 'src/grossmeister/ttable.rs')
-rw-r--r-- | src/grossmeister/ttable.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/grossmeister/ttable.rs b/src/grossmeister/ttable.rs new file mode 100644 index 0000000..4bf2398 --- /dev/null +++ b/src/grossmeister/ttable.rs @@ -0,0 +1,44 @@ +use crate::moves::Move; + +use super::Grossmeister; + +/// https://www.chessprogramming.org/Node_Types +#[derive(Debug, PartialEq, Clone, Copy)] +pub enum NodeType { + /// Principal variation node - exact score + PV, + /// Fail-high + Cut, + /// Fail-low + All, +} + +#[derive(Debug, PartialEq, Clone, Copy)] +pub struct TranspositionTableItem { + /// Zobrist hash of this position + pub hash: u64, + pub mov: Move, + pub depth: u8, + pub score: f32, + pub node_type: NodeType, +} + +pub const TTABLE_SIZE: u64 = 2u64.pow(24); +pub type TranspositionTable = Vec<Option<TranspositionTableItem>>; + + +impl Grossmeister { + /// Find current transposition in Transposition Table + pub fn transposition(&self) -> Option<TranspositionTableItem> { + match self.transposition_table[(self.board.hash % TTABLE_SIZE) as usize] { + Some(item) => { + if item.hash == self.board.hash { + return Some(item) + } + None + } + None => None + } + } + +} |