From afe7cb91c0ef7f6a07f38447a1b08376f7b9fa5d Mon Sep 17 00:00:00 2001 From: eug-vs Date: Tue, 31 Jan 2023 22:26:54 +0300 Subject: fix: correct king bonus table --- src/board/engine.rs | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'src/board/engine.rs') diff --git a/src/board/engine.rs b/src/board/engine.rs index 8521082..835a9b6 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -17,17 +17,19 @@ pub struct PerftResult { } const PAWN_BONUS: [f32; 64] = [ - 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, - 0.10, 0.10, 0.20, 0.30, 0.30, 0.20, 0.10, 0.10, - 0.05, 0.05, 0.10, 0.25, 0.25, 0.10, 0.05, 0.05, - 0.00, 0.00, 0.00, 0.20, 0.20, 0.00, 0.00, 0.00, - 0.05, -0.05, -0.10, 0.00, 0.00, -0.10, -0.05, 0.05, - 0.05, 0.10, 0.10, -0.20, -0.20, 0.10, 0.10, 0.05, - 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 + // 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, + 0.10, 0.10, 0.20, 0.30, 0.30, 0.20, 0.10, 0.10, + 0.05, 0.05, 0.10, 0.25, 0.25, 0.10, 0.05, 0.05, + 0.00, 0.00, 0.00, 0.20, 0.20, 0.00, 0.00, 0.00, + 0.05, -0.05, -0.10, 0.00, 0.00, -0.10, -0.05, 0.05, + 0.05, 0.10, 0.10, -0.20, -0.20, 0.10, 0.10, 0.05, + 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 ]; const KNIGHT_BONUS: [f32; 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, -0.30, 0.00, 0.10, 0.15, 0.15, 0.10, 0.00, -0.30, @@ -39,19 +41,21 @@ const KNIGHT_BONUS: [f32; 64] = [ ]; const BISHOP_BONUS: [f32; 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, -0.10, 0.00, 0.05, 0.10, 0.10, 0.05, 0.00, -0.10, -0.10, 0.05, 0.05, 0.10, 0.10, 0.05, 0.05, -0.10, -0.10, 0.00, 0.10, 0.10, 0.10, 0.10, 0.00, -0.10, -0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10, -0.10, - -0.10, 0.05, 0.00, 0.00, 0.00, 0.00, 0.05, -0.10, + -0.10, 0.25, 0.00, 0.00, 0.00, 0.00, 0.25, -0.10, -0.20, -0.10, -0.10, -0.10, -0.10, -0.10, -0.10, -0.20, ]; const ROOK_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, - 0.05, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.05, + 0.05, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.05, -0.05, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -0.05, -0.05, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -0.05, -0.05, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -0.05, @@ -61,6 +65,7 @@ const ROOK_BONUS: [f32; 64] = [ ]; const QUEEN_BONUS: [f32; 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, -0.10, 0.00, 0.05, 0.05, 0.05, 0.05, 0.00, -0.10, @@ -72,6 +77,7 @@ const QUEEN_BONUS: [f32; 64] = [ ]; const KING_BONUS: [f32; 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, -0.30, -0.40, -0.40, -0.50, -0.50, -0.40, -0.40, -0.30, @@ -79,7 +85,7 @@ const KING_BONUS: [f32; 64] = [ -0.20, -0.30, -0.30, -0.40, -0.40, -0.30, -0.30, -0.20, -0.10, -0.20, -0.20, -0.20, -0.20, -0.20, -0.20, -0.10, 0.20, 0.20, 0.00, 0.00, 0.00, 0.00, 0.20, 0.20, - 0.20, 0.30, 0.10, 0.00, 0.00, 0.10, 0.30, 0.20 + 0.20, 0.10, 0.30, -0.20, 0.00, 0.10, 0.30, 0.20 ]; @@ -575,7 +581,7 @@ impl Board { #[cfg(test)] mod tests { use std::time::Duration; - use crate::{board::{Board, engine::PerftResult, Color}, square::Square, moves::{Move, MoveKind}}; + use crate::{board::{Board, engine::{PerftResult, KING_BONUS}, Color}, square::Square, moves::{Move, MoveKind}}; use super::VALUE_WIN; #[test] @@ -659,6 +665,19 @@ mod tests { ); } + #[test] + fn castle_bonus() { + assert_eq!(KING_BONUS[Square::E1.mirror() as usize], 0.0); + assert!(KING_BONUS[Square::G1.mirror() as usize] > 0.0); + assert!(KING_BONUS[Square::C1.mirror() as usize] > 0.0); + assert!(KING_BONUS[Square::D1.mirror() as usize] < 0.0); + + assert_eq!(KING_BONUS[Square::E8 as usize], 0.0); + assert!(KING_BONUS[Square::G8 as usize] > 0.0); + assert!(KING_BONUS[Square::C8 as usize] > 0.0); + assert!(KING_BONUS[Square::D8 as usize] < 0.0); + } + mod evaluation { use crate::{moves::{Move, MoveKind}, square::Square}; -- cgit v1.2.3