feat: horse movegen

This commit is contained in:
dogeystamp 2024-10-20 13:54:12 -04:00
parent 35f0585979
commit a30a695275

View File

@ -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",