From a30a695275dd906dcb869eb3402086125c67483b Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sun, 20 Oct 2024 13:54:12 -0400 Subject: [PATCH] feat: horse movegen --- src/movegen.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/movegen.rs b/src/movegen.rs index 75bf10f..0289434 100644 --- a/src/movegen.rs +++ b/src/movegen.rs @@ -469,6 +469,30 @@ impl PseudoMoveGen for BoardState { } } } + for src in squares!(Knight) { + let (r, c) = src.to_row_col(); + let dirs = [ + (2, 1), + (1, 2), + (-1, 2), + (-2, 1), + (-2, -1), + (-1, -2), + (1, -2), + (2, -1), + ]; + for dir in dirs { + let nr = r as isize + dir.0; + let nc = c as isize + dir.1; + if let Ok(dest) = Square::from_row_col_signed(nr, nc) { + ret.push(Move { + src, + dest, + move_type: MoveType::Normal, + }) + } + } + } ret } } @@ -504,6 +528,28 @@ mod tests { MoveType::Normal, )], ), + // horse test + ( + "8/2r1r3/1n3q2/3N4/8/2p5/8/8 w - - 0 1", + vec![( + "d5", + vec![ + "f6", "e7", "c7", "b6", "b4", "c3", "e3", "f4", + ], + MoveType::Normal, + )], + ), + // horse (blocked by boundary) + ( + "8/8/8/8/8/6n1/5n2/7N w - - 0 1", + vec![( + "h1", + vec![ + "f2", "g3" + ], + MoveType::Normal, + )], + ), // white pawn promotion ( "q1q5/1P6/8/8/8/8/8/8 w - - 0 1",