[board] Implement a custom PartialEq on Position
We don't need to compare cached data. The load-bearing parts of a Position are: player to move, position of all pieces, flags, and en passant status. Inspiration for this implementation came from the FEN spec. It specifies all these in the string.
This commit is contained in:
parent
1f873879bb
commit
b002442b42
1 changed files with 10 additions and 1 deletions
|
@ -12,7 +12,7 @@ use chessfriend_bitboard::BitBoard;
|
|||
use chessfriend_core::{Color, Piece, PlacedPiece, Shape, Square};
|
||||
use std::{cell::OnceCell, fmt};
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq)]
|
||||
pub struct Position {
|
||||
color_to_move: Color,
|
||||
flags: Flags,
|
||||
|
@ -300,6 +300,15 @@ impl Default for Position {
|
|||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Position {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.pieces == other.pieces
|
||||
&& self.color_to_move == other.color_to_move
|
||||
&& self.flags == other.flags
|
||||
&& self.en_passant_square == other.en_passant_square
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Position {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", DiagramFormatter::new(self))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue