diff --git a/board/src/piece_sets.rs b/board/src/piece_sets.rs index 97ada5c..98a9d40 100644 --- a/board/src/piece_sets.rs +++ b/board/src/piece_sets.rs @@ -5,7 +5,10 @@ mod mailbox; use self::mailbox::Mailbox; use chessfriend_bitboard::{BitBoard, IterationDirection}; use chessfriend_core::{Color, Piece, Shape, Square}; -use std::ops::BitOr; +use std::{ + hash::{Hash, Hasher}, + ops::BitOr, +}; use thiserror::Error; #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] @@ -21,9 +24,9 @@ pub enum PlacePieceError { ExisitingPiece { piece: Piece, square: Square }, } -/// The internal data structure of a [Board] that efficiently manages the +/// The internal data structure of a [`Board`] that efficiently manages the /// placement of pieces on the board. -#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)] +#[derive(Clone, Debug, Default, Eq)] pub struct PieceSet { mailbox: Mailbox, color_occupancy: [BitBoard; Color::NUM], @@ -140,6 +143,20 @@ impl PieceSet { } } +impl Hash for PieceSet { + fn hash(&self, state: &mut H) { + self.color_occupancy.hash(state); + self.shape_occupancy.hash(state); + } +} + +impl PartialEq for PieceSet { + fn eq(&self, other: &Self) -> bool { + self.color_occupancy == other.color_occupancy + && self.shape_occupancy == other.shape_occupancy + } +} + #[cfg(test)] mod tests { use super::*;