1
0
Fork 0

new constructor for squares

This commit is contained in:
Paul-Nicolas Madelaine 2025-11-03 16:20:47 +01:00
parent c28c40186e
commit 263bb0ddb6
7 changed files with 59 additions and 44 deletions

View file

@ -420,14 +420,14 @@ impl Position {
SanInner::Castle(CastlingSide::Short) => (
Role::King,
Role::King,
Square::new(File::E, self.turn().home_rank()).bitboard(),
Square::new(File::G, self.turn().home_rank()).bitboard(),
Square::from_coords(File::E, self.turn().home_rank()).bitboard(),
Square::from_coords(File::G, self.turn().home_rank()).bitboard(),
),
SanInner::Castle(CastlingSide::Long) => (
Role::King,
Role::King,
Square::new(File::E, self.turn().home_rank()).bitboard(),
Square::new(File::C, self.turn().home_rank()).bitboard(),
Square::from_coords(File::E, self.turn().home_rank()).bitboard(),
Square::from_coords(File::C, self.turn().home_rank()).bitboard(),
),
SanInner::Normal {
role,
@ -1278,7 +1278,7 @@ 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::new(
setup.en_passant = OptionSquare::new(Some(Square::from_coords(
from.file(),
match setup.turn {
Color::White => Rank::Third,
@ -1308,12 +1308,12 @@ fn aux_play_normal(setup: &mut Setup, role: Role, from: Square, target: Square)
setup.p_b_q &= mask;
setup.n_b_k &= mask;
setup.r_q_k &= mask;
if target == Square::new(File::H, setup.turn.promotion_rank()) {
if target == Square::from_coords(File::H, setup.turn.promotion_rank()) {
setup
.castling_rights
.unset(!setup.turn, CastlingSide::Short);
}
if target == Square::new(File::A, setup.turn.promotion_rank()) {
if target == Square::from_coords(File::A, setup.turn.promotion_rank()) {
setup.castling_rights.unset(!setup.turn, CastlingSide::Long);
}
match role {
@ -1336,10 +1336,10 @@ fn aux_play_normal(setup: &mut Setup, role: Role, from: Square, target: Square)
}
Role::Rook => {
setup.r_q_k |= to;
if from == Square::new(File::H, setup.turn.home_rank()).bitboard() {
if from == Square::from_coords(File::H, setup.turn.home_rank()).bitboard() {
setup.castling_rights.unset(setup.turn, CastlingSide::Short);
}
if from == Square::new(File::A, setup.turn.home_rank()).bitboard() {
if from == Square::from_coords(File::A, setup.turn.home_rank()).bitboard() {
setup.castling_rights.unset(setup.turn, CastlingSide::Long);
}
}
@ -1386,12 +1386,16 @@ fn aux_play_castle(setup: &mut Setup, side: CastlingSide) {
let rank = setup.turn.home_rank();
let (king_flip, rook_flip) = match side {
CastlingSide::Short => (
Square::new(File::E, rank).bitboard() | Square::new(File::G, rank).bitboard(),
Square::new(File::H, rank).bitboard() | Square::new(File::F, rank).bitboard(),
Square::from_coords(File::E, rank).bitboard()
| Square::from_coords(File::G, rank).bitboard(),
Square::from_coords(File::H, rank).bitboard()
| Square::from_coords(File::F, rank).bitboard(),
),
CastlingSide::Long => (
Square::new(File::E, rank).bitboard() | Square::new(File::C, rank).bitboard(),
Square::new(File::A, rank).bitboard() | Square::new(File::D, rank).bitboard(),
Square::from_coords(File::E, rank).bitboard()
| Square::from_coords(File::C, rank).bitboard(),
Square::from_coords(File::A, rank).bitboard()
| Square::from_coords(File::D, rank).bitboard(),
),
};