diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-02-23 15:35:15 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-02-23 15:35:15 +0300 |
commit | a7a26f7810e9bc5fec6020324a83a2a89b69ff79 (patch) | |
tree | f6f36e359f7373141fbdbf62bcaab2358ab1f790 /src/grossmeister | |
parent | 573d674bffd9275ea98abc119e747e74e2abc941 (diff) | |
download | chessnost-a7a26f7810e9bc5fec6020324a83a2a89b69ff79.tar.gz |
refactor: implement Player trait for Grossmeister
Diffstat (limited to 'src/grossmeister')
-rw-r--r-- | src/grossmeister/evaluation.rs | 16 | ||||
-rw-r--r-- | src/grossmeister/mod.rs | 26 | ||||
-rw-r--r-- | src/grossmeister/perft.rs | 0 |
3 files changed, 26 insertions, 16 deletions
diff --git a/src/grossmeister/evaluation.rs b/src/grossmeister/evaluation.rs index 61d375c..308f320 100644 --- a/src/grossmeister/evaluation.rs +++ b/src/grossmeister/evaluation.rs @@ -198,7 +198,7 @@ impl Grossmeister { }; let pawn_attacked_squares = opponent_pawns.serialize().iter().fold(0u64, |acc, square| { - acc | self.attacks.pawn[color.flip() as usize][*square as usize] + acc | self.board.attacks.pawn[color.flip() as usize][*square as usize] }); // Exclude squares controlled by enemy pawns from mobility @@ -219,20 +219,20 @@ impl Grossmeister { } None => 0, }; - mobility += (self.attacks.pawn[color as usize][source as usize] & (opponent_occupancy | ep_bitboard)).pop_count() as f32; - mobility += (self.attacks.pawn_pushes[color as usize][source as usize] & empty).pop_count() as f32; + mobility += (self.board.attacks.pawn[color as usize][source as usize] & (opponent_occupancy | ep_bitboard)).pop_count() as f32; + mobility += (self.board.attacks.pawn_pushes[color as usize][source as usize] & empty).pop_count() as f32; } let able_to_double_push_mask = match color { Color::White => empty >> 8, Color::Black => empty << 8, }; for source in (*piece & able_to_double_push_mask).serialize() { - mobility += (self.attacks.pawn_double_pushes[color as usize][source as usize] & empty).pop_count() as f32; + mobility += (self.board.attacks.pawn_double_pushes[color as usize][source as usize] & empty).pop_count() as f32; } } Piece::King => { for source in piece.serialize() { - mobility += (self.attacks.king[source as usize] & (empty | opponent_occupancy)).pop_count() as f32; + mobility += (self.board.attacks.king[source as usize] & (empty | opponent_occupancy)).pop_count() as f32; // Castling let king_home_position = match color { @@ -280,17 +280,17 @@ impl Grossmeister { } Piece::Knight => { for source in piece.serialize() { - mobility += (self.attacks.knight[source as usize] & (empty | opponent_occupancy)).pop_count() as f32; + mobility += (self.board.attacks.knight[source as usize] & (empty | opponent_occupancy)).pop_count() as f32; } } Piece::Bishop => { for source in piece.serialize() { - mobility += (self.attacks.bishop(self.board.occupancy, source) & (empty | opponent_occupancy)).pop_count() as f32; + mobility += (self.board.attacks.bishop(self.board.occupancy, source) & (empty | opponent_occupancy)).pop_count() as f32; } } Piece::Rook => { for source in piece.serialize() { - mobility += (self.attacks.rook(self.board.occupancy, source) & (empty | opponent_occupancy)).pop_count() as f32; + mobility += (self.board.attacks.rook(self.board.occupancy, source) & (empty | opponent_occupancy)).pop_count() as f32; } } Piece::Queen => { 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) + } +} diff --git a/src/grossmeister/perft.rs b/src/grossmeister/perft.rs deleted file mode 100644 index e69de29..0000000 --- a/src/grossmeister/perft.rs +++ /dev/null |