From a7a26f7810e9bc5fec6020324a83a2a89b69ff79 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 23 Feb 2023 15:35:15 +0300 Subject: refactor: implement Player trait for Grossmeister --- src/grossmeister/mod.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/grossmeister/mod.rs') diff --git a/src/grossmeister/mod.rs b/src/grossmeister/mod.rs index d9e5d1d..d07aeee 100644 --- a/src/grossmeister/mod.rs +++ b/src/grossmeister/mod.rs @@ -1,4 +1,6 @@ -use crate::{board::Board, attacks::Attacks}; +use std::time::Duration; + +use crate::{board::Board, player::Player, moves::Move}; use self::ttable::{TranspositionTable, TTABLE_SIZE}; mod ttable; @@ -9,12 +11,9 @@ mod search; /// This structure represents a player, it stores his knowledge /// and experience about the game. pub struct Grossmeister { - pub board: Board, - - /// Array of pre-computed attack tables. - /// This structure allows Grossmeister to calculate attacks of the pieces - /// as fast as possible using his big brain. - attacks: Attacks, + /// 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. @@ -22,13 +21,24 @@ pub struct Grossmeister { transposition_table: TranspositionTable, } +impl Default for Grossmeister { + fn default() -> Self { + Self::new(Board::default()) + } +} impl Grossmeister { pub fn new(board: Board) -> Self { Self { board, - attacks: Attacks::new(), transposition_table: vec![None; TTABLE_SIZE as usize], } } } + +impl Player for Grossmeister { + fn analyze(&mut self, board: Board, duration: Duration) -> (f32, Vec) { + self.board = board; // Copy the board into GM's head + self.iterative_deepening(8, duration, true) + } +} -- cgit v1.2.3