chessfriend/moves/src/castle.rs

92 lines
2.7 KiB
Rust
Raw Normal View History

// Eryn Wells <eryn@erynwells.me>
use chessfriend_bitboard::BitBoard;
2024-02-09 20:00:47 -08:00
use chessfriend_core::Square;
2024-02-09 20:00:47 -08:00
#[repr(u8)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Castle {
2024-02-09 20:00:47 -08:00
KingSide = 0,
QueenSide = 1,
}
pub(crate) struct CastlingParameters {
2024-02-09 20:00:47 -08:00
/// Origin squares of the king and rook.
origin_squares: Squares,
/// Target or destination squares for the king and rook.
target_squares: Squares,
/// The set of squares that must be clear of any pieces in order to perform this castle.
clear_squares: BitBoard,
2024-02-09 20:00:47 -08:00
/// The set of squares that must not be attacked in order to perform this castle.
check_squares: BitBoard,
}
#[derive(Debug)]
pub(crate) struct Squares {
pub king: Square,
pub rook: Square,
}
impl Castle {
pub const ALL: [Castle; 2] = [Castle::KingSide, Castle::QueenSide];
2024-02-09 20:00:47 -08:00
/// Parameters for each castling move, organized by color and board-side.
const PARAMETERS: [[CastlingParameters; 2]; 2] = [
[
2024-02-09 20:00:47 -08:00
CastlingParameters {
origin_squares: Squares {
king: Square::E1,
rook: Square::H1,
},
target_squares: Squares {
king: Square::G1,
rook: Square::F1,
},
clear_squares: BitBoard::new(0b01100000),
check_squares: BitBoard::new(0b01110000),
},
2024-02-09 20:00:47 -08:00
CastlingParameters {
origin_squares: Squares {
king: Square::E1,
rook: Square::A1,
},
target_squares: Squares {
king: Square::C1,
rook: Square::D1,
},
clear_squares: BitBoard::new(0b00001110),
check_squares: BitBoard::new(0b00011100),
},
],
[
2024-02-09 20:00:47 -08:00
CastlingParameters {
origin_squares: Squares {
king: Square::E8,
rook: Square::H8,
},
target_squares: Squares {
king: Square::G8,
rook: Square::F8,
},
clear_squares: BitBoard::new(0b01100000 << 8 * 7),
check_squares: BitBoard::new(0b01110000 << 8 * 7),
},
2024-02-09 20:00:47 -08:00
CastlingParameters {
origin_squares: Squares {
king: Square::E8,
rook: Square::A8,
},
target_squares: Squares {
king: Square::C8,
rook: Square::D8,
},
clear_squares: BitBoard::new(0b00001110 << 8 * 7),
check_squares: BitBoard::new(0b00011100 << 8 * 7),
},
],
];
}