[board] Replace PieceSet's derived Hash and PartialEq with bespoke implementation
The piece set duplicates some data to make lookups more efficient. Only use the necessary, unique data for these functions.
This commit is contained in:
		
							parent
							
								
									34e8c08c36
								
							
						
					
					
						commit
						086f9c5666
					
				
					 1 changed files with 20 additions and 3 deletions
				
			
		|  | @ -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<H: Hasher>(&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::*; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue