Rename en passant square method on Position and implement a getter for the capture square
Position::en_passant_square → en_passant_target_square Position::en_passant_capture_square
This commit is contained in:
parent
c55b7c4877
commit
cc23ee2d90
4 changed files with 20 additions and 5 deletions
|
|
@ -95,7 +95,7 @@ impl ToFen for Position {
|
||||||
write!(
|
write!(
|
||||||
fen_string,
|
fen_string,
|
||||||
" {}",
|
" {}",
|
||||||
if let Some(en_passant_square) = self.en_passant_square() {
|
if let Some(en_passant_square) = self.en_passant_target_square() {
|
||||||
en_passant_square.to_string()
|
en_passant_square.to_string()
|
||||||
} else {
|
} else {
|
||||||
"-".to_string()
|
"-".to_string()
|
||||||
|
|
|
||||||
|
|
@ -292,7 +292,7 @@ mod tests {
|
||||||
new_position.piece_on_square(Square::E4),
|
new_position.piece_on_square(Square::E4),
|
||||||
Some(piece!(White Pawn on E4))
|
Some(piece!(White Pawn on E4))
|
||||||
);
|
);
|
||||||
assert_eq!(new_position.en_passant_square(), Some(Square::E3));
|
assert_eq!(new_position.en_passant_target_square(), Some(Square::E3));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ impl Builder {
|
||||||
flags: position.flags(),
|
flags: position.flags(),
|
||||||
pieces,
|
pieces,
|
||||||
kings: [Some(white_king), Some(black_king)],
|
kings: [Some(white_king), Some(black_king)],
|
||||||
en_passant_square: position.en_passant_square(),
|
en_passant_square: position.en_passant_target_square(),
|
||||||
ply_counter: position.ply_counter(),
|
ply_counter: position.ply_counter(),
|
||||||
move_number: position.move_number(),
|
move_number: position.move_number(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
sight::SightExt,
|
sight::SightExt,
|
||||||
};
|
};
|
||||||
use chessfriend_bitboard::BitBoard;
|
use chessfriend_bitboard::BitBoard;
|
||||||
use chessfriend_core::{Color, Piece, PlacedPiece, Shape, Square};
|
use chessfriend_core::{Color, Piece, PlacedPiece, Rank, Shape, Square};
|
||||||
use std::{cell::OnceCell, fmt};
|
use std::{cell::OnceCell, fmt};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq)]
|
#[derive(Clone, Debug, Eq)]
|
||||||
|
|
@ -182,10 +182,25 @@ impl Position {
|
||||||
Pieces::new(&self, color)
|
Pieces::new(&self, color)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn en_passant_square(&self) -> Option<Square> {
|
/// If en passant is available in this position, the square a pawn will move
|
||||||
|
/// to if it captures en passant.
|
||||||
|
pub fn en_passant_target_square(&self) -> Option<Square> {
|
||||||
self.en_passant_square
|
self.en_passant_square
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If en passant is available in this position, the square on which the
|
||||||
|
/// captured pawn is sitting.
|
||||||
|
pub fn en_passant_capture_square(&self) -> Option<Square> {
|
||||||
|
let target_square = self.en_passant_square?;
|
||||||
|
|
||||||
|
let file = target_square.file();
|
||||||
|
Some(match target_square.rank() {
|
||||||
|
Rank::THREE => Square::from_file_rank(file, Rank::FOUR),
|
||||||
|
Rank::SIX => Square::from_file_rank(file, Rank::SEVEN),
|
||||||
|
_ => unreachable!(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn _sight_of_player(&self, player: Color, pieces: &PieceBitBoards) -> BitBoard {
|
fn _sight_of_player(&self, player: Color, pieces: &PieceBitBoards) -> BitBoard {
|
||||||
let en_passant_square = self.en_passant_square;
|
let en_passant_square = self.en_passant_square;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue