aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-08-16 03:37:14 +0300
committereug-vs <eugene@eug-vs.xyz>2023-08-16 03:37:14 +0300
commita6fe0cf85e3664013f50bad0f77d3003c3c2700b (patch)
tree78847b68a88a5a97cb6b695885848ff594d0fcce
parente2102adf0bc0c7feb5f3e02dbf32655608dca1d7 (diff)
downloadchessnost-a6fe0cf85e3664013f50bad0f77d3003c3c2700b.tar.gz
feat: add basic draw evaluation
-rw-r--r--src/grossmeister/evaluation.rs32
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();