[board] Replace active player and move properties on Board with MoveCounter instance
This commit is contained in:
parent
58cbe07136
commit
cd60a453aa
3 changed files with 24 additions and 49 deletions
|
@ -1,7 +1,8 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use crate::{
|
||||
display::DiagramFormatter, piece_sets::PlacePieceError, Castle, EnPassant, Flags, PieceSet,
|
||||
display::DiagramFormatter, piece_sets::PlacePieceError, Castle, EnPassant, Flags, MoveCounter,
|
||||
PieceSet,
|
||||
};
|
||||
use chessfriend_bitboard::BitBoard;
|
||||
use chessfriend_core::{Color, Piece, PlacedPiece, Shape, Square};
|
||||
|
@ -9,12 +10,10 @@ use std::iter::Iterator;
|
|||
|
||||
#[derive(Clone, Debug, Eq)]
|
||||
pub struct Board {
|
||||
player_to_move: Color,
|
||||
flags: Flags,
|
||||
pieces: PieceSet,
|
||||
en_passant: Option<EnPassant>,
|
||||
half_move_counter: u16,
|
||||
full_move_number: u16,
|
||||
pub move_counter: MoveCounter,
|
||||
}
|
||||
|
||||
impl Board {
|
||||
|
@ -46,7 +45,6 @@ impl Board {
|
|||
];
|
||||
|
||||
Self {
|
||||
player_to_move: Color::White,
|
||||
pieces: PieceSet::new([WHITE_PIECES, BLACK_PIECES]),
|
||||
..Default::default()
|
||||
}
|
||||
|
@ -72,22 +70,7 @@ impl Board {
|
|||
|
||||
#[must_use]
|
||||
pub fn player_to_move(&self) -> Color {
|
||||
self.player_to_move
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn move_number(&self) -> u16 {
|
||||
self.full_move_number
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn ply_counter(&self) -> u16 {
|
||||
self.half_move_counter
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn flags(&self) -> &Flags {
|
||||
&self.flags
|
||||
self.move_counter.active_color
|
||||
}
|
||||
|
||||
/// Returns `true` if the player has the right to castle on the given side
|
||||
|
@ -199,12 +182,10 @@ impl Board {
|
|||
impl Default for Board {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
player_to_move: Color::default(),
|
||||
flags: Flags::default(),
|
||||
pieces: PieceSet::default(),
|
||||
en_passant: None,
|
||||
half_move_counter: 0,
|
||||
full_move_number: 1,
|
||||
move_counter: MoveCounter::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -212,9 +193,9 @@ impl Default for Board {
|
|||
impl PartialEq for Board {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.pieces == other.pieces
|
||||
&& self.player_to_move == other.player_to_move
|
||||
&& self.flags == other.flags
|
||||
&& self.en_passant == other.en_passant
|
||||
&& self.move_counter == other.move_counter
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue