aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-08-23 22:01:27 +0300
committereug-vs <eugene@eug-vs.xyz>2023-08-23 22:01:27 +0300
commit85fbcdadec3853a92da6d434dbc94bb85bdfdcfe (patch)
tree516f43f661f569c8d6d1a5e69c8d8f592f1df5d0
parente4ab4673997348249371b2afcb315827aff93305 (diff)
downloadchessnost-85fbcdadec3853a92da6d434dbc94bb85bdfdcfe.tar.gz
feat: tune evaluation parameters
-rw-r--r--src/grossmeister/evaluation.rs33
1 files changed, 13 insertions, 20 deletions
diff --git a/src/grossmeister/evaluation.rs b/src/grossmeister/evaluation.rs
index dafc33a..6669545 100644
--- a/src/grossmeister/evaluation.rs
+++ b/src/grossmeister/evaluation.rs
@@ -1,9 +1,7 @@
-use crate::{board::{piece::Piece, color::Color, CastlingSide}, bitboard::{BitboardFns, Bitboard}, square::Square};
+use crate::{board::{piece::Piece, color::Color, CastlingSide}, bitboard::{Bitboard, BitboardFns}, square::Square};
use super::Grossmeister;
-static A_FILE: Bitboard = 0x0101010101010101;
-
const PAWN_BONUS: [f32; 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,
@@ -16,7 +14,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_ENDGAME: [f32; 64] = [
+const PAWN_BONUS_PASSER_ENDGAME: [f32; 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,
@@ -101,11 +99,11 @@ const KING_BONUS_ENGAME: [f32; 64] = [
];
impl Grossmeister {
- pub fn passer_count(&self, color: Color) -> f32 {
+ pub fn passer_mask(&self, color: Color) -> Bitboard {
let black_pawns = self.board.piece_sets[Piece::PawnBlack as usize];
let white_pawns = self.board.piece_sets[Piece::Pawn as usize];
- let mask = match color {
+ match color {
Color::Black => {
let mut front_fill = white_pawns.nort_fill().nort_one();
front_fill |= front_fill.east_one() | front_fill.west_one();
@@ -116,12 +114,7 @@ impl Grossmeister {
front_fill |= front_fill.east_one() | front_fill.west_one();
white_pawns & !front_fill
}
- };
-
- (mask & match color {
- Color::White => white_pawns,
- Color::Black => black_pawns,
- }).pop_count() as f32
+ }
}
pub fn is_dead_position(&self) -> bool {
@@ -173,7 +166,7 @@ impl Grossmeister {
let fileset = pawns.nort_fill().sout_fill();
// Does not matter west/east, each island has both sides
let islands_west_files = fileset & !fileset.east_one();
- islands_west_files.pop_count() as f32
+ (islands_west_files.pop_count() / 8) as f32
}
/// Compute total bonus for well-positioned pieces
@@ -181,8 +174,8 @@ impl Grossmeister {
pub fn pst_bonus(&self, color: Color, is_endgame: bool) -> f32 {
self.board.pieces_by_color(color).iter().enumerate().fold(0., |total, (piece_index, bitboard)| {
let pst = match Piece::from(piece_index).without_color() {
- Piece::Pawn => if is_endgame {
- PAWN_BONUS_ENDGAME
+ Piece::Pawn => if is_endgame && (bitboard & self.passer_mask(color) > 0) {
+ PAWN_BONUS_PASSER_ENDGAME
} else {
PAWN_BONUS
}
@@ -252,23 +245,23 @@ impl Grossmeister {
let material_advantage = self.material(color) - self.material(opponent_color);
let mobility_advantage = self.mobility(color) - self.mobility(opponent_color);
let pawn_shield_advantage = self.pawn_shield(color) - self.pawn_shield(opponent_color);
- let passer_advantage = self.passer_count(color) - self.passer_count(opponent_color);
let pawn_islands_advantage = self.pawn_islands(opponent_color) - self.pawn_islands(color);
+ // Middlegame eval, assumming all pieces are on the Board
let middlegame_eval =
mobility_advantage * 0.05 +
- pawn_shield_advantage * 0.15 +
+ pawn_shield_advantage * 0.20 +
pawn_islands_advantage * 0.10 +
- passer_advantage * 0.05 +
(self.pst_bonus(color, false) - self.pst_bonus(opponent_color, false));
+ // Engame eval, assuming no pieces are left on the Board (only kings and pawns)
let endgame_eval =
mobility_advantage * 0.03 +
- pawn_shield_advantage * 0.20 +
+ pawn_shield_advantage * 0.05 +
pawn_islands_advantage * 0.15 +
- passer_advantage * 0.10 +
(self.pst_bonus(color, true) - self.pst_bonus(opponent_color, true));
+ // Interpolate evalutaion based on amount of pieces to remove discontinuity
let phase = self.phase();
let tapered_eval = (middlegame_eval * phase as f32 + endgame_eval * (240 - phase) as f32) / 240.;