aboutsummaryrefslogtreecommitdiff
path: root/src/board/engine.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-01-28 23:19:05 +0300
committereug-vs <eugene@eug-vs.xyz>2023-01-28 23:22:45 +0300
commit60341dd02fbe1ff320d600f8dd0f3e59dba61c2b (patch)
treefa48a8b7abb7c8e408f1944534a91213cde75a53 /src/board/engine.rs
parent5be5c3b838358a688512468332b04eeec13c4315 (diff)
downloadchessnost-60341dd02fbe1ff320d600f8dd0f3e59dba61c2b.tar.gz
test: some evaluation sanity checks
Diffstat (limited to 'src/board/engine.rs')
-rw-r--r--src/board/engine.rs122
1 files changed, 119 insertions, 3 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs
index 65851cf..53d2564 100644
--- a/src/board/engine.rs
+++ b/src/board/engine.rs
@@ -195,7 +195,7 @@ impl Board {
let king_tropism_penalty = self.king_tropism(color) - self.king_tropism(opponent_color);
- material_advantage + 0.1 * mobility_advantage - 0.5 * pawn_structure_penalty + king_tropism_penalty * opponent_material / 100.0
+ material_advantage + 0.1 * mobility_advantage - 0.5 * pawn_structure_penalty + king_tropism_penalty * opponent_material / 150.0
}
/// Evaluate move for move ordering, prioritizing efficient captures
@@ -453,9 +453,125 @@ mod tests {
#[test]
fn material() {
let board = Board::new();
- assert_eq!(board.material(Color::Black), 38.0);
- assert_eq!(board.material(Color::White), 38.0);
+ assert_eq!(board.material(Color::Black), 40.0);
+ assert_eq!(board.material(Color::White), 40.0);
}
+ mod evaluation {
+ use crate::{moves::{Move, MoveKind}, square::Square};
+
+ use super::*;
+
+ #[test]
+ fn initial_eval() {
+ let board = Board::new();
+ assert_eq!(board.evaluate(None), 0.0);
+ }
+
+ #[test]
+ fn king_tropism() {
+ let mut board = Board::new();
+ board.make_move(Move { source: Square::D1, target: Square::F5, kind: MoveKind::Quiet });
+ let score = board.evaluate(None);
+ board.print();
+ println!("Score {}", score);
+
+ assert!(score < 0.0);
+ assert!(score > -1.0);
+ }
+
+ #[test]
+ fn white_winning() {
+ let fen = String::from("8/5pk1/6p1/R4b1p/3P4/1P2N3/P1r2PPP/R5K1 b - - 1 27");
+ let board = Board::from_FEN(fen);
+ let score = board.evaluate(None);
+ board.print();
+ println!("Score {}", score);
+
+ assert!(score > 7.0);
+ }
+
+ #[test]
+ fn black_winning() {
+ let fen = String::from("8/p7/1k4K1/8/4P3/8/PP5r/8 b - - 1 38");
+ let board = Board::from_FEN(fen);
+ let score = board.evaluate(None);
+ board.print();
+ println!("Score {}", score);
+
+ assert!(score < -4.0);
+ }
+
+ #[test]
+ fn encourage_center_pawns() {
+ let score1 = {
+ let fen = String::from("rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 2");
+ let board = Board::from_FEN(fen);
+ let score = board.evaluate(None);
+ board.print();
+ println!("Score {}", score);
+ score
+ };
+
+ let score2 = {
+ let fen = String::from("rnbqkbnr/pppp1ppp/8/4p3/2P5/8/PP1PPPPP/RNBQKBNR w KQkq - 0 2");
+ let board = Board::from_FEN(fen);
+ let score = board.evaluate(None);
+ board.print();
+ println!("Score {}", score);
+ score
+ };
+
+ assert!(score1 > score2);
+ }
+
+ #[test]
+ fn discourage_edge_knights() {
+ let score1 = {
+ let fen = String::from("r1bqkbnr/pppp1ppp/2n5/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 2 3");
+ let board = Board::from_FEN(fen);
+ let score = board.evaluate(None);
+ board.print();
+ println!("Score {}", score);
+ score
+ };
+
+ let score2 = {
+ let fen = String::from("r1bqkbnr/pppp1ppp/2n5/4p3/4P3/7N/PPPP1PPP/RNBQKB1R w KQkq - 2 3");
+ let board = Board::from_FEN(fen);
+ let score = board.evaluate(None);
+ board.print();
+ println!("Score {}", score);
+ score
+ };
+
+ assert!(score1 > score2);
+ }
+
+ #[test]
+ fn mirrored_evaluation() {
+ let score1 = {
+ let fen = String::from("r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1");
+ let board = Board::from_FEN(fen);
+ let score = board.evaluate(None);
+ board.print();
+ println!("Score {}", score);
+ score
+ };
+
+ let score2 = {
+ let fen = String::from("r2q1rk1/pP1p2pp/Q4n2/bbp1p3/Np6/1B3NBn/pPPP1PPP/R3K2R b KQ - 0 1 ");
+ let mut board = Board::from_FEN(fen);
+ board.ply += 1; // TODO: remove me when FEN parsing includes side to move
+ let score = board.evaluate(None);
+ board.print();
+ println!("Score {}", score);
+ score
+ };
+
+ assert_eq!(score1.abs(), score2.abs());
+ }
+ }
+
}