35 lines
933 B
Rust
35 lines
933 B
Rust
|
use chessfriend_core::Color;
|
||
|
|
||
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||
|
pub struct MoveCounter {
|
||
|
/// The player who's turn it is to move.
|
||
|
pub active_color: Color,
|
||
|
/// The number of completed turns. A turn finishes when every player has moved.
|
||
|
pub fullmove_number: u16,
|
||
|
/// The number of moves by all players since the last pawn advance or capture.
|
||
|
pub halfmove_number: u16,
|
||
|
}
|
||
|
|
||
|
impl MoveCounter {
|
||
|
pub fn advance(&mut self, should_reset_halfmove_number: bool) {
|
||
|
self.active_color = self.active_color.next();
|
||
|
|
||
|
self.fullmove_number += 1;
|
||
|
self.halfmove_number = if should_reset_halfmove_number {
|
||
|
0
|
||
|
} else {
|
||
|
self.halfmove_number + 1
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl Default for MoveCounter {
|
||
|
fn default() -> Self {
|
||
|
Self {
|
||
|
active_color: Color::default(),
|
||
|
fullmove_number: 0,
|
||
|
halfmove_number: 0,
|
||
|
}
|
||
|
}
|
||
|
}
|