aboutsummaryrefslogtreecommitdiff
path: root/src/grossmeister/mod.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-02-23 15:35:15 +0300
committereug-vs <eugene@eug-vs.xyz>2023-02-23 15:35:15 +0300
commita7a26f7810e9bc5fec6020324a83a2a89b69ff79 (patch)
treef6f36e359f7373141fbdbf62bcaab2358ab1f790 /src/grossmeister/mod.rs
parent573d674bffd9275ea98abc119e747e74e2abc941 (diff)
downloadchessnost-a7a26f7810e9bc5fec6020324a83a2a89b69ff79.tar.gz
refactor: implement Player trait for Grossmeister
Diffstat (limited to 'src/grossmeister/mod.rs')
-rw-r--r--src/grossmeister/mod.rs26
1 files changed, 18 insertions, 8 deletions
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<Move>) {
+ self.board = board; // Copy the board into GM's head
+ self.iterative_deepening(8, duration, true)
+ }
+}