From 42ccddc12b4eac953705d29af353c358c31ab392 Mon Sep 17 00:00:00 2001 From: Paul-Nicolas Madelaine Date: Wed, 17 Dec 2025 23:30:13 +0100 Subject: [PATCH] wip: misc --- src/position.rs | 34 +++++++++++++--------------------- tests/tests.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/position.rs b/src/position.rs index df32349..4e8bd5c 100644 --- a/src/position.rs +++ b/src/position.rs @@ -308,12 +308,6 @@ impl Position { from: Bitboard, to: Bitboard, } - impl MoveGenImpl { - #[inline] - fn new(role: Role, from: Bitboard, to: Bitboard) -> Self { - Self { role, from, to } - } - } impl MoveGen for MoveGenImpl { #[inline] fn roles(&self, role: Role) -> bool { @@ -348,7 +342,6 @@ impl Position { to, promotion, } = uci; - let role = self.0.role(from).ok_or(InvalidUciMove::Illegal)?; #[inline] fn aux<'l, const ROLE: u8>( position: &'l Position, @@ -356,13 +349,18 @@ impl Position { from: Square, to: Square, ) -> Result, InvalidUciMove> { - let mut moves = MoveGenImpl::::new(role, from.bitboard(), to.bitboard()); + let mut moves = MoveGenImpl:: { + role, + from: from.bitboard(), + to: to.bitboard(), + }; let raw = position .generate_moves(&mut moves) .break_value() .ok_or(InvalidUciMove::Illegal)?; Ok(unsafe { Move::new(position, raw) }) } + let role = self.0.role(from).ok_or(InvalidUciMove::Illegal)?; let promotion = if role == Role::Pawn { promotion.unwrap_or(Role::Pawn) } else if promotion.is_some() { @@ -381,18 +379,6 @@ impl Position { found: Option, found_other: bool, } - impl MoveGenImpl { - #[inline] - fn new(role: Role, from: Bitboard, to: Bitboard) -> Self { - Self { - role, - from, - to, - found: None, - found_other: false, - } - } - } impl MoveGen for MoveGenImpl { #[inline] fn roles(&self, role: Role) -> bool { @@ -466,7 +452,13 @@ impl Position { from: Bitboard, to: Bitboard, ) -> Result, InvalidSan> { - let mut moves = MoveGenImpl::::new(role, from, to); + let mut moves = MoveGenImpl:: { + role, + from, + to, + found: None, + found_other: false, + }; let ControlFlow::Continue(()) = position.generate_moves(&mut moves); match moves.found { None => Err(InvalidSan::Illegal), diff --git a/tests/tests.rs b/tests/tests.rs index 1efe806..206e547 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -2,6 +2,7 @@ use eschac::board::*; use eschac::position::*; use eschac::san::*; use eschac::setup::*; +use eschac::uci::*; static P1: &'static str = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -"; static P2: &'static str = "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -"; @@ -319,6 +320,38 @@ fn san() { ); } +#[test] +fn uci_move() { + let position = Setup::from_text_record("3qk3/2P5/8/8/8/8/8/B3K2R w K -") + .unwrap() + .into_position() + .unwrap(); + for uci in ["a1a1", "a1a2", "c7b8q", "c7c8", "c7d8"].map(|s| s.parse::().unwrap()) { + assert!(uci.to_move(&position).is_err(), "{uci}"); + } + for uci in ["c7c8q", "c7d8n", "e1g1"].map(|s| s.parse::().unwrap()) { + assert!(uci.to_move(&position).is_ok(), "{uci}"); + } + assert_eq!( + "h1h8" + .parse::() + .unwrap() + .to_move(&position) + .unwrap() + .role(), + Role::Rook, + ); + assert_eq!( + "a1h8" + .parse::() + .unwrap() + .to_move(&position) + .unwrap() + .role(), + Role::Bishop, + ); +} + #[test] fn max_legal_moves() { let position = Setup::from_text_record("R6R/3Q4/1Q4Q1/4Q3/2Q4Q/Q4Q2/pp1Q4/kBNN1KB1 w - -")