[board, core, moves, position] Implement castling

Implement a new method on Position that evaluates whether the active color can castle
on a given wing of the board. Then, implement making a castling move in the position.

Make a new Wing enum in the core crate to specify kingside or queenside. Replace the
Castle enum from the board crate with this one. This caused a lot of churn...

Along the way fix a bunch of tests.

Note: there's still no way to actually make a castling move in explorer.
This commit is contained in:
Eryn Wells 2025-05-19 16:50:30 -07:00
parent 6816e350eb
commit 0c1863acb9
18 changed files with 499 additions and 258 deletions

View file

@ -1,5 +1,9 @@
// Eryn Wells <eryn@erynwells.me>
mod wings;
pub use wings::Wing;
use crate::Color;
use std::fmt;
use thiserror::Error;
@ -519,7 +523,7 @@ mod tests {
fn bad_algebraic_input() {
assert!("a0".parse::<Square>().is_err());
assert!("j3".parse::<Square>().is_err());
assert!("a11".parse::<Square>().is_err());
assert!("a9".parse::<Square>().is_err());
assert!("b-1".parse::<Square>().is_err());
assert!("a 1".parse::<Square>().is_err());
assert!("".parse::<Square>().is_err());

View file

@ -0,0 +1,22 @@
// Eryn Wells <eryn@erynwells.me>
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Wing {
KingSide = 0,
QueenSide = 1,
}
impl Wing {
pub const NUM: usize = 2;
pub const ALL: [Wing; Self::NUM] = [Self::KingSide, Self::QueenSide];
}
impl std::fmt::Display for Wing {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Wing::KingSide => write!(f, "kingside"),
Wing::QueenSide => write!(f, "queenside"),
}
}
}

View file

@ -8,6 +8,6 @@ pub mod shapes;
mod macros;
pub use colors::Color;
pub use coordinates::{Direction, File, Rank, Square};
pub use coordinates::{Direction, File, Rank, Square, Wing};
pub use pieces::{Piece, PlacedPiece};
pub use shapes::Shape;