diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/grossmeister/evaluation.rs | 32 |
1 files changed, 32 insertions, 0 deletions
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(); |