aboutsummaryrefslogtreecommitdiff
path: root/src/grossmeister/mod.rs
blob: db9cb5877c55a7ceb4f5cebcf99df4cc362b849b (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
45
46
47
48
49
50
51
use std::sync::{atomic::AtomicBool, Arc};

use crate::{board::Board, player::Player, moves::Move};
use self::ttable::{TranspositionTable, TTABLE_SIZE};

mod ttable;
mod evaluation;
mod search;
mod UCI;

/// Grossmeister is a powerful entity that plays the game of Chess.
/// This structure represents a player, it stores his knowledge
/// and experience about the game.
#[derive(Clone)]
pub struct Grossmeister {
    /// GM's internal board representation
    /// This is usually a copy of a real board
    board: Board,

    /// Transposition table is a cache of all positions that Grossmeister
    /// has seen and evaluated.
    /// It's indexex by Zobrist hash of a position mod size
    transposition_table: TranspositionTable,

    should_halt: Arc<AtomicBool>,
    debug: bool,
}

impl Default for Grossmeister {
    fn default() -> Self {
        Self::new(Board::default())
    }
}

impl Grossmeister {
    pub fn new(board: Board) -> Self {
        Self {
            board,
            transposition_table: vec![None; TTABLE_SIZE as usize],
            should_halt: Arc::new(AtomicBool::new(false)),
            debug: false,
        }
    }
}

impl Player for Grossmeister {
    fn analyze(&mut self, board: Board) -> (f32, Vec<Move>) {
        self.board = board; // Copy the board into GM's head
        self.iterative_deepening(8)
    }
}