From 00f3d33edfdd3cdb8e329875a1af9acccf4d457a Mon Sep 17 00:00:00 2001 From: DragonDuck24 Date: Wed, 21 Oct 2026 16:58:16 -0400 Subject: [PATCH] fixes --- cli/src/commands.rs | 1 + cli/src/commands/benchmark.rs | 2 +- cli/src/commands/selfplay.rs | 1 + engine/src/net/encoding.rs | 47 +++++++++++++++++++++++++++-------- uci/src/main.rs | 2 +- 5 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 cli/src/commands/selfplay.rs diff --git a/cli/src/commands.rs b/cli/src/commands.rs index 3de8630..ae534c1 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -1,3 +1,4 @@ pub mod benchmark; pub mod play; +pub mod selfplay; pub mod train; diff --git a/cli/src/commands/benchmark.rs b/cli/src/commands/benchmark.rs index 8b13789..fec4af1 100644 --- a/cli/src/commands/benchmark.rs +++ b/cli/src/commands/benchmark.rs @@ -1 +1 @@ - +pub fn run() {} diff --git a/cli/src/commands/selfplay.rs b/cli/src/commands/selfplay.rs new file mode 100644 index 0000000..fec4af1 --- /dev/null +++ b/cli/src/commands/selfplay.rs @@ -0,0 +1 @@ +pub fn run() {} diff --git a/engine/src/net/encoding.rs b/engine/src/net/encoding.rs index f95fb9e..5e9d80d 100644 --- a/engine/src/net/encoding.rs +++ b/engine/src/net/encoding.rs @@ -249,25 +249,20 @@ pub fn decode_move(idx: usize, board: &Board) -> Option { return None; } - // Default pawn moves to final rank (perspective fr == 6 -> tr == 7) to Queen promotion if not underpromotion + let stm = board.side_to_move(); + + // Default pawn moves to final rank (perspective fr == 6 -> tr == 7) to Queen promotion if not underpromotion. + // fr/ff are perspective coordinates, so deorient back to real squares before inspecting the board. if promo.is_none() && fr == 6 && tr == 7 && dy == 1 && dx.abs() <= 1 - && board.piece_on(Square::make_square( - Rank::from_index(fr as usize), - File::from_index(ff as usize), - )) == Some(Piece::Pawn) + && board.piece_on(deorient_square(ff, fr, stm)) == Some(Piece::Pawn) { promo = Some(Piece::Queen); } - // if fr == 6 && tr == 7 && dy == 1 && dx.abs() <= 1 && promo.is_none() { - // promo = Some(Piece::Queen); - // } - - let stm = board.side_to_move(); let from = deorient_square(ff, fr, stm); let to = deorient_square(tf, tr, stm); @@ -349,4 +344,36 @@ mod tests { assert_eq!(mv, dec); } + + #[test] + fn queen_promotion_roundtrip_black() { + // Black pawn on d2, white king on h1, black king on e8, black to move. + // d2-d1 is a legal promotion; d1 is empty. + let board = Board::from_str("4k3/8/8/8/8/8/3p4/7K b - - 0 1").unwrap(); + + let from = Square::make_square(Rank::Second, File::D); + let to = Square::make_square(Rank::First, File::D); + + let mv = ChessMove::new(from, to, Some(Piece::Queen)); + + let enc = encode_move(mv, Color::Black).unwrap(); + let dec = decode_move(enc, &board).unwrap(); + + assert_eq!(mv, dec); + } + + #[test] + fn underpromotion_roundtrip_black() { + let board = Board::from_str("4k3/8/8/8/8/8/3p4/7K b - - 0 1").unwrap(); + + let from = Square::make_square(Rank::Second, File::D); + let to = Square::make_square(Rank::First, File::D); + + let mv = ChessMove::new(from, to, Some(Piece::Knight)); + + let enc = encode_move(mv, Color::Black).unwrap(); + let dec = decode_move(enc, &board).unwrap(); + + assert_eq!(mv, dec); + } } diff --git a/uci/src/main.rs b/uci/src/main.rs index fd1ab14..92729ca 100644 --- a/uci/src/main.rs +++ b/uci/src/main.rs @@ -1,5 +1,5 @@ use chess::{ChessMove, Game}; -use engine::{legal_action_mask, Engine}; +use engine::Engine; use std::io; use std::str::FromStr;