1
0
Fork 0

new square constructors

This commit is contained in:
Paul-Nicolas Madelaine 2025-11-05 23:37:02 +01:00
parent de321719f4
commit ad1c4c57ad
7 changed files with 59 additions and 44 deletions

View file

@ -91,7 +91,9 @@ impl Setup {
};
(file < 8).then_some(())?;
setup.set(
unsafe { Square::new(File::transmute(file), Rank::transmute(rank)) },
unsafe {
Square::from_coords(File::transmute(file), Rank::transmute(rank))
},
Some(Piece { role, color }),
);
file += 1;
@ -126,7 +128,7 @@ impl Setup {
match s.next()? {
b'-' => (),
file => setup.set_en_passant_target_square(Some(Square::new(
file => setup.set_en_passant_target_square(Some(Square::from_coords(
File::from_ascii(file)?,
Rank::from_ascii(s.next()?)?,
))),
@ -154,7 +156,7 @@ impl Setup {
for rank in Rank::all().into_iter().rev() {
let mut count = 0;
for file in File::all() {
match self.get(Square::new(file, rank)) {
match self.get(Square::from_coords(file, rank)) {
Some(piece) => {
if count > 0 {
w.write_char(char::from_u32('0' as u32 + count).unwrap())?;
@ -411,11 +413,14 @@ impl Setup {
&& !(pieces
.get(color)
.get(Role::King)
.contains(Square::new(File::E, color.home_rank()))
.contains(Square::from_coords(File::E, color.home_rank()))
&& pieces
.get(color)
.get(Role::Rook)
.contains(Square::new(side.rook_origin_file(), color.home_rank())))
.contains(Square::from_coords(
side.rook_origin_file(),
color.home_rank(),
)))
})
}) {
reasons.add(IllegalPositionReason::InvalidCastlingRights);
@ -426,7 +431,7 @@ impl Setup {
Color::White => (Rank::Sixth, Rank::Fifth),
Color::Black => (Rank::Third, Rank::Fourth),
};
let pawn_square = Square::new(en_passant.file(), pawn_rank);
let pawn_square = Square::from_coords(en_passant.file(), pawn_rank);
en_passant.rank() != target_rank
|| blockers.contains(en_passant)
|| !pieces.get(!self.turn).get(Role::Pawn).contains(pawn_square)