aboutsummaryrefslogtreecommitdiff
path: root/src/grossmeister
diff options
context:
space:
mode:
Diffstat (limited to 'src/grossmeister')
-rw-r--r--src/grossmeister/evaluation.rs16
-rw-r--r--src/grossmeister/mod.rs26
-rw-r--r--src/grossmeister/perft.rs0
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