[board] Implement ply and full move counters on Position
Pipe these numbers through the Builders
This commit is contained in:
parent
829d9af52c
commit
dbbf2d4c46
3 changed files with 63 additions and 2 deletions
|
@ -28,6 +28,7 @@ pub enum ValidatedMove {
|
|||
promotion: Option<Shape>,
|
||||
flags: Flags,
|
||||
en_passant_square: Option<Square>,
|
||||
increment_ply: bool,
|
||||
},
|
||||
Castle {
|
||||
castle: Castle,
|
||||
|
@ -140,6 +141,7 @@ where
|
|||
promotion: mv.promotion(),
|
||||
flags,
|
||||
en_passant_square,
|
||||
increment_ply: !(mv.is_capture() || piece.is_pawn()),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -150,6 +152,9 @@ impl<'p> Builder<'p, ValidatedMove> {
|
|||
pub fn build(&self) -> Position {
|
||||
let player = self.position.player_to_move();
|
||||
|
||||
let updated_move_number =
|
||||
self.position.move_number() + if player == Color::Black { 1 } else { 0 };
|
||||
|
||||
match self.move_to_make {
|
||||
ValidatedMove::RegularMove {
|
||||
from_square,
|
||||
|
@ -159,6 +164,7 @@ impl<'p> Builder<'p, ValidatedMove> {
|
|||
promotion,
|
||||
flags,
|
||||
en_passant_square,
|
||||
increment_ply,
|
||||
} => {
|
||||
let mut pieces = self.position.piece_bitboards().clone();
|
||||
|
||||
|
@ -174,11 +180,19 @@ impl<'p> Builder<'p, ValidatedMove> {
|
|||
pieces.move_piece(moving_piece.piece(), from_square, to_square);
|
||||
}
|
||||
|
||||
let ply = if increment_ply {
|
||||
self.position.ply_counter() + 1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
Position::new(
|
||||
self.position.player_to_move().other(),
|
||||
flags,
|
||||
pieces,
|
||||
en_passant_square,
|
||||
ply,
|
||||
updated_move_number,
|
||||
)
|
||||
}
|
||||
ValidatedMove::Castle {
|
||||
|
@ -202,7 +216,14 @@ impl<'p> Builder<'p, ValidatedMove> {
|
|||
*pieces.bitboard_for_color_mut(player) &=
|
||||
!(king_from | rook_from) | (king_to | rook_to);
|
||||
|
||||
Position::new(player.other(), flags, pieces, None)
|
||||
Position::new(
|
||||
player.other(),
|
||||
flags,
|
||||
pieces,
|
||||
None,
|
||||
self.position.ply_counter() + 1,
|
||||
updated_move_number,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue