aboutsummaryrefslogtreecommitdiff
path: root/src/grossmeister/evaluation.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/grossmeister/evaluation.rs')
-rw-r--r--src/grossmeister/evaluation.rs27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/grossmeister/evaluation.rs b/src/grossmeister/evaluation.rs
index 6fc4149..1b57f5a 100644
--- a/src/grossmeister/evaluation.rs
+++ b/src/grossmeister/evaluation.rs
@@ -4,7 +4,10 @@ use crate::{board::{piece::Piece, color::Color, CastlingSide}, bitboard::{Bitboa
use super::Grossmeister;
-const PAWN_BONUS: [f32; 64] = [
+/// Score in pawns (not centipawns)
+pub type Score = f32;
+
+const PAWN_BONUS: [Score; 64] = [
// A B C D E F G H
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
0.50, 0.50, 0.50, 0.50, 0.50, 0.50, 0.50, 0.50,
@@ -16,7 +19,7 @@ const PAWN_BONUS: [f32; 64] = [
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00
];
-const PAWN_BONUS_PASSER_ENDGAME: [f32; 64] = [
+const PAWN_BONUS_PASSER_ENDGAME: [Score; 64] = [
// A B C D E F G H
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00,
@@ -28,7 +31,7 @@ const PAWN_BONUS_PASSER_ENDGAME: [f32; 64] = [
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
];
-const KNIGHT_BONUS: [f32; 64] = [
+const KNIGHT_BONUS: [Score; 64] = [
// A B C D E F G H
-0.50, -0.40, -0.30, -0.30, -0.30, -0.30, -0.40, -0.50,
-0.40, -0.20, 0.00, 0.00, 0.00, 0.00, -0.20, -0.40,
@@ -40,7 +43,7 @@ const KNIGHT_BONUS: [f32; 64] = [
-0.50, -0.40, -0.30, -0.30, -0.30, -0.30, -0.40, -0.50,
];
-const BISHOP_BONUS: [f32; 64] = [
+const BISHOP_BONUS: [Score; 64] = [
// A B C D E F G H
-0.20, -0.10, -0.10, -0.10, -0.10, -0.10, -0.10, -0.20,
-0.10, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -0.10,
@@ -52,7 +55,7 @@ const BISHOP_BONUS: [f32; 64] = [
-0.20, -0.10, -0.10, -0.10, -0.10, -0.10, -0.10, -0.20,
];
-const ROOK_BONUS: [f32; 64] = [
+const ROOK_BONUS: [Score; 64] = [
// A B C D E F G H
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
0.05, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.05,
@@ -64,7 +67,7 @@ const ROOK_BONUS: [f32; 64] = [
0.00, 0.00, 0.00, 0.05, 0.05, 0.00, 0.00, 0.00
];
-const QUEEN_BONUS: [f32; 64] = [
+const QUEEN_BONUS: [Score; 64] = [
// A B C D E F G H
-0.20, -0.10, -0.10, -0.05, -0.05, -0.10, -0.10, -0.20,
-0.10, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -0.10,
@@ -76,7 +79,7 @@ const QUEEN_BONUS: [f32; 64] = [
-0.20, -0.10, -0.10, -0.05, -0.05, -0.10, -0.10, -0.20
];
-const KING_BONUS: [f32; 64] = [
+const KING_BONUS: [Score; 64] = [
// A B C D E F G H
-0.30, -0.40, -0.40, -0.50, -0.50, -0.40, -0.40, -0.30,
-0.30, -0.40, -0.40, -0.50, -0.50, -0.40, -0.40, -0.30,
@@ -88,7 +91,7 @@ const KING_BONUS: [f32; 64] = [
0.20, 0.10, 0.30, -0.20, 0.00, 0.10, 0.30, 0.20
];
-const KING_BONUS_ENGAME: [f32; 64] = [
+const KING_BONUS_ENGAME: [Score; 64] = [
// A B C D E F G H
-0.50, -0.40, -0.30, -0.20, -0.20, -0.30, -0.40, -0.50,
-0.30, -0.20, -0.10, 0.00, 0.00, -0.10, -0.20, -0.30,
@@ -209,7 +212,7 @@ impl Grossmeister {
/// Evaluate a position relative to the current player
- pub fn evaluate(&self) -> f32 {
+ pub fn evaluate(&self) -> Score {
let color = self.board.color();
let opponent_color = color.flip();
@@ -243,9 +246,11 @@ impl Grossmeister {
let phase = self.phase();
let tapered_eval = (middlegame_eval * phase as f32 + endgame_eval * (240 - phase) as f32) / 240.;
- (material_advantage + tapered_eval)
+ let eval = (material_advantage + tapered_eval)
.min(if winnable { INFINITY } else { 0.0 }) // Can not score > 0 if not winnable
- .max(if loseable { -INFINITY } else { 0.0 }) // Can not score < 0 if not loseable
+ .max(if loseable { -INFINITY } else { 0.0 }); // Can not score < 0 if not loseable
+
+ (eval * 100.0).round() / 100.0
}
/// Count pseudo-legal moves without actually generating them