aboutsummaryrefslogtreecommitdiff
path: root/src/board/engine.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-01-31 22:26:54 +0300
committereug-vs <eugene@eug-vs.xyz>2023-01-31 22:26:54 +0300
commitafe7cb91c0ef7f6a07f38447a1b08376f7b9fa5d (patch)
treee187372045c0a35079f631230bc2d71b9c4ca696 /src/board/engine.rs
parentfd0d63aa8fafc6cb46699d75604c329427d158a9 (diff)
downloadchessnost-afe7cb91c0ef7f6a07f38447a1b08376f7b9fa5d.tar.gz
fix: correct king bonus table
Diffstat (limited to 'src/board/engine.rs')
-rw-r--r--src/board/engine.rs43
1 files changed, 31 insertions, 12 deletions
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};