1
0
Fork 0

get rid of OptionSquare

This commit is contained in:
Paul-Nicolas Madelaine 2025-11-29 14:12:20 +01:00
parent 4c137d3c95
commit ebab07f5ae
3 changed files with 21 additions and 67 deletions

View file

@ -32,7 +32,7 @@ pub struct Setup {
/// bitboards = [pawns | bishops | queens, knights | bishops | kings, rooks | queens | kings, black]
pub(crate) bitboards: [Bitboard; 4],
pub(crate) turn: Color,
pub(crate) en_passant: OptionSquare,
pub(crate) en_passant: Option<Square>,
pub(crate) castling_rights: CastlingRights,
}
@ -43,7 +43,7 @@ impl Setup {
Self {
bitboards: [Bitboard(0); 4],
turn: Color::White,
en_passant: OptionSquare::None,
en_passant: None,
castling_rights: CastlingRights::new(),
}
}
@ -208,7 +208,7 @@ impl Setup {
w.write_char(' ')?;
match self.en_passant.try_into_square() {
match self.en_passant {
Some(sq) => {
w.write_char(sq.file().to_char())?;
w.write_char(sq.rank().to_char())?;
@ -245,7 +245,7 @@ impl Setup {
/// Returns the optional en passant target square.
#[inline]
pub fn en_passant_target_square(&self) -> Option<Square> {
self.en_passant.try_into_square()
self.en_passant
}
/// Sets the occupancy of a square.
@ -307,7 +307,7 @@ impl Setup {
/// Sets the en passant target square.
#[inline]
pub fn set_en_passant_target_square(&mut self, square: Option<Square>) {
self.en_passant = OptionSquare::new(square);
self.en_passant = square;
}
/// Returns the quad-bitboard representation of the board.
@ -341,11 +341,7 @@ impl Setup {
(black ^ (p_b_q | n_b_k | r_q_k)).mirror(),
],
turn: !self.turn,
en_passant: self
.en_passant
.try_into_square()
.map(|square| OptionSquare::from_square(square.mirror()))
.unwrap_or(OptionSquare::None),
en_passant: self.en_passant.map(|square| square.mirror()),
castling_rights: self.castling_rights.mirror(),
}
}
@ -460,7 +456,7 @@ impl Setup {
reasons.add(IllegalPositionReason::InvalidCastlingRights);
}
if self.en_passant.try_into_square().is_some_and(|en_passant| {
if self.en_passant.is_some_and(|en_passant| {
let (target_rank, pawn_rank) = match self.turn {
Color::White => (Rank::Sixth, Rank::Fifth),
Color::Black => (Rank::Third, Rank::Fourth),
@ -473,7 +469,7 @@ impl Setup {
reasons.add(IllegalPositionReason::InvalidEnPassant);
}
if self.en_passant.try_into_square().is_some_and(|en_passant| {
if self.en_passant.is_some_and(|en_passant| {
let blockers = blockers
& !en_passant.bitboard().trans(match self.turn {
Color::White => Direction::South,