aboutsummaryrefslogtreecommitdiff
path: root/src/grossmeister/ttable.rs
blob: 4bf2398c7273747c50b8fc9d46777ea70c9d79fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
        }
    }

}