get rid of OptionSquare
This commit is contained in:
parent
4c137d3c95
commit
ebab07f5ae
3 changed files with 21 additions and 67 deletions
|
|
@ -94,7 +94,7 @@ impl Position {
|
|||
],
|
||||
turn: Color::White,
|
||||
castling_rights: CastlingRights::full(),
|
||||
en_passant: OptionSquare::None,
|
||||
en_passant: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ impl Position {
|
|||
/// Returns `true` if taking en passant is legal on the position.
|
||||
#[must_use]
|
||||
pub fn en_passant_is_legal(&self) -> bool {
|
||||
if self.as_setup().en_passant == OptionSquare::None {
|
||||
if self.as_setup().en_passant == None {
|
||||
return false;
|
||||
}
|
||||
struct MoveGenImpl {
|
||||
|
|
@ -192,7 +192,11 @@ impl Position {
|
|||
}
|
||||
}
|
||||
let mut moves = MoveGenImpl {
|
||||
to: self.as_setup().en_passant.bitboard(),
|
||||
to: self
|
||||
.as_setup()
|
||||
.en_passant
|
||||
.map(|square| square.bitboard())
|
||||
.unwrap_or(Bitboard::new()),
|
||||
};
|
||||
self.generate_moves(&mut moves).is_break()
|
||||
}
|
||||
|
|
@ -204,7 +208,7 @@ impl Position {
|
|||
/// passant before calling this function.
|
||||
#[inline]
|
||||
pub fn remove_en_passant_target_square(&mut self) {
|
||||
self.0.en_passant = OptionSquare::None;
|
||||
self.0.en_passant = None
|
||||
}
|
||||
|
||||
/// Removes the castling rights for the given color and side, if any.
|
||||
|
|
@ -255,7 +259,7 @@ impl Position {
|
|||
checkers.is_empty().then(|| {
|
||||
Self(Setup {
|
||||
turn: !turn,
|
||||
en_passant: OptionSquare::None,
|
||||
en_passant: None,
|
||||
..self.0.clone()
|
||||
})
|
||||
})
|
||||
|
|
@ -801,7 +805,7 @@ impl Position {
|
|||
),
|
||||
)?;
|
||||
// en passant
|
||||
if let Some(to) = en_passant.try_into_square() {
|
||||
if let Some(to) = en_passant {
|
||||
if global_mask_to.contains(to) {
|
||||
let capture_square = unsafe {
|
||||
// SAFETY: the position is legal
|
||||
|
|
@ -907,7 +911,7 @@ impl Position {
|
|||
pub(crate) unsafe fn play_unchecked(&mut self, m: RawMove) {
|
||||
let Self(setup) = self;
|
||||
|
||||
setup.en_passant = OptionSquare::None;
|
||||
setup.en_passant = None;
|
||||
|
||||
let RawMove {
|
||||
kind,
|
||||
|
|
@ -927,13 +931,13 @@ impl Position {
|
|||
MoveType::PawnAttackPromotion => aux_play_normal(setup, role, from, to),
|
||||
MoveType::PawnDoubleAdvance => {
|
||||
aux_play_pawn_advance(setup, Role::Pawn, from, to);
|
||||
setup.en_passant = OptionSquare::new(Some(Square::from_coords(
|
||||
setup.en_passant = Some(Square::from_coords(
|
||||
from.file(),
|
||||
match setup.turn {
|
||||
Color::White => Rank::Third,
|
||||
Color::Black => Rank::Sixth,
|
||||
},
|
||||
)));
|
||||
));
|
||||
}
|
||||
MoveType::EnPassant => {
|
||||
let direction = !setup.turn.forward();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue