Move a whole bunch of stuff to the new chessfriend_board package
This commit is contained in:
parent
797606785e
commit
1d82d27f84
12 changed files with 1130 additions and 41 deletions
48
board/src/en_passant.rs
Normal file
48
board/src/en_passant.rs
Normal file
|
@ -0,0 +1,48 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use chessfriend_core::{Rank, Square};
|
||||
|
||||
/// En passant information.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct EnPassant {
|
||||
target: Square,
|
||||
capture: Square,
|
||||
}
|
||||
|
||||
impl EnPassant {
|
||||
fn _capture_square(target: Square) -> Option<Square> {
|
||||
let (file, rank) = target.file_rank();
|
||||
match rank {
|
||||
Rank::THREE => Some(Square::from_file_rank(file, Rank::FOUR)),
|
||||
Rank::SIX => Some(Square::from_file_rank(file, Rank::FIVE)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return en passant information for a particular target square. The target
|
||||
/// square is the square a pawn capturing en passant will move to.
|
||||
///
|
||||
/// Return `None` if the square is not eligible for en passant.
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```
|
||||
/// use chessfriend_board::en_passant::EnPassant;
|
||||
/// use chessfriend_core::Square;
|
||||
/// assert!(EnPassant::from_target_square(Square::E3).is_some());
|
||||
/// assert!(EnPassant::from_target_square(Square::B4).is_none());
|
||||
/// ```
|
||||
pub fn from_target_square(target: Square) -> Option<Self> {
|
||||
Self::_capture_square(target).map(|capture| Self { target, capture })
|
||||
}
|
||||
|
||||
/// The square the capturing piece will move to.
|
||||
pub fn target_square(self) -> Square {
|
||||
self.target
|
||||
}
|
||||
|
||||
/// The square on which the captured pawn sits.
|
||||
pub fn capture_square(self) -> Square {
|
||||
self.capture
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue