Skip to content

Commit

Permalink
chore: some cleanup stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
raklaptudirm committed Dec 12, 2024
1 parent 556baa2 commit 66d1774
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions games/src/chess/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::interface::MoveStore;
use super::castling::CastlingRightsParseError;
use super::castling::Dimension;
use super::castling::Rights;
use super::castling::Side;
use super::movegen;
use super::MoveFlag;

Expand Down Expand Up @@ -134,21 +135,13 @@ impl PositionType for Position {

let source_pc = unsafe { source_pc.unwrap_unchecked() };

if !m.flag().is_promotion() && !m.flag().is_castling() {
board.insert(m.target(), source_pc);
}

board.castling.rights -= board.castling.get_updates(m.source())
| board.castling.get_updates(m.target());

if source_pc.piece() == Piece::Pawn || target_pc.is_some() {
board.half_move_clock = 0;
}

board.en_passant_target = None;

match m.flag() {
MoveFlag::Normal => {}
MoveFlag::Normal => board.insert(m.target(), source_pc),
MoveFlag::NPromotion
| MoveFlag::BPromotion
| MoveFlag::RPromotion
Expand All @@ -160,32 +153,27 @@ impl PositionType for Position {
),
),
MoveFlag::EnPassant => {
board.insert(m.target(), source_pc);
board.remove(unsafe {
m.target().down(board.side_to_move).unwrap_unchecked()
});
}
MoveFlag::DoublePush => {
board.insert(m.target(), source_pc);
board.en_passant_target = Some(unsafe {
m.target().down(board.side_to_move).unwrap_unchecked()
});
}
MoveFlag::CastleASide => {
let (king, rook) =
Dimension::from(board.side_to_move, castling::Side::A)
.get_targets();
board.insert(
king,
ColoredPiece::new(Piece::King, board.side_to_move),
);
board.insert(
rook,
ColoredPiece::new(Piece::Rook, board.side_to_move),
);
}
MoveFlag::CastleHSide => {
let (king, rook) =
Dimension::from(board.side_to_move, castling::Side::H)
.get_targets();
MoveFlag::CastleHSide | MoveFlag::CastleASide => {
let (king, rook) = Dimension::from(
board.side_to_move,
if m.flag() == MoveFlag::CastleHSide {
Side::H
} else {
Side::A
},
)
.get_targets();
board.insert(
king,
ColoredPiece::new(Piece::King, board.side_to_move),
Expand All @@ -198,6 +186,9 @@ impl PositionType for Position {
}

board.half_move_clock += 1;
if source_pc.piece() == Piece::Pawn || target_pc.is_some() {
board.half_move_clock = 0;
}
board.side_to_move = !board.side_to_move;

board
Expand Down

0 comments on commit 66d1774

Please sign in to comment.