diff --git a/src/lib.rs b/src/lib.rs index e5a9c35..20ffc4c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,8 +100,8 @@ pub struct PieceErr; /// Color and piece. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct ColPiece { - pc: Piece, - col: Color, + pub pc: Piece, + pub col: Color, } impl TryFrom for ColPiece { diff --git a/src/main.rs b/src/main.rs index 8415afb..088de22 100644 --- a/src/main.rs +++ b/src/main.rs @@ -160,9 +160,45 @@ fn cmd_go(mut tokens: std::str::SplitWhitespace<'_>, state: &mut MainState) { } /// Print static evaluation of the position. +/// +/// This calculation is inefficient compared to what happens in the real engine, but it offers more +/// information. fn cmd_eval(mut _tokens: std::str::SplitWhitespace<'_>, state: &mut MainState) { let res = eval_metrics(&state.board); - println!("STATIC EVAL (negative black, positive white):\n- pst: {}\n- king distance: {} ({} distance)\n- phase: {}\n- total: {}", res.pst_eval, res.king_distance_eval, res.king_distance, res.phase, res.total_eval); + println!("STATIC EVAL (negative black, positive white):"); + println!("- pst total: {}", res.pst_eval); + let tables = [ + ("midgame", &chess_inator::eval::PST_MIDGAME), + ("endgame", &chess_inator::eval::PST_ENDGAME), + ]; + for (name, pst) in tables { + println!(" {name}"); + let mut cumulative_table = 0; + use Piece::*; + for col in [Color::White, Color::Black] { + for pc_type in [Pawn, Knight, Bishop, Rook, Queen, King] { + let mut cumulative = 0; + let sqs = state.board[col][pc_type]; + let pc = ColPiece { pc: pc_type, col }; + print!(" {:?} {:?}\n ", col, pc_type); + for sq in sqs { + let score = pst[pc.pc][pc.col][sq] * EvalInt::from(pc.col.sign()); + cumulative += score; + print!("{} {}; ", sq, score); + } + println!(); + println!(" total {}: {}", char::from(pc), cumulative); + cumulative_table += cumulative; + } + } + println!(" TOTAL {name}: {cumulative_table}"); + } + println!( + "- king distance: {} ({})", + res.king_distance_eval, res.king_distance + ); + println!("- phase: {}", res.phase); + println!("- total: {}", res.total_eval); } /// Root UCI parser.