From a6fe0cf85e3664013f50bad0f77d3003c3c2700b Mon Sep 17 00:00:00 2001 From: eug-vs Date: Wed, 16 Aug 2023 03:37:14 +0300 Subject: feat: add basic draw evaluation --- src/grossmeister/evaluation.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src') diff --git a/src/grossmeister/evaluation.rs b/src/grossmeister/evaluation.rs index 572fa63..4512dcc 100644 --- a/src/grossmeister/evaluation.rs +++ b/src/grossmeister/evaluation.rs @@ -125,8 +125,40 @@ impl Grossmeister { } } + pub fn is_dead_position(&self) -> bool { + let non_minor_exists = [ + Piece::Pawn, + Piece::PawnBlack, + Piece::Rook, + Piece::RookBlack, + Piece::Queen, + Piece::QueenBlack + ].iter().any(|&piece| { + self.board.piece_sets[piece as usize].pop_count() > 0 + }); + + if non_minor_exists { + return false; + } + + let minor_pieces = [ + Piece::Knight, + Piece::KnightBlack, + Piece::Bishop, + Piece::BishopBlack + ].iter().fold(0, |acc, &piece| { + acc + self.board.piece_sets[piece as usize].pop_count() + }); + + minor_pieces <= 1 + } + /// Evaluate a position relative to the current player pub fn evaluate(&self) -> f32 { + if self.is_dead_position() { + return 0.0 + } + let color = self.board.color(); let opponent_color = color.flip(); -- cgit v1.2.3