[board, moves] Reorganize castling_right API on Board

Board::color_has_castling_right takes an Option<Color> which it unwraps. With that
unwrapped Color, it can call…

Board::color_has_castling_right_unwrapped, which performs the evaluation with a
non-Option Color.

Clean up some imports.
This commit is contained in:
Eryn Wells 2025-06-17 08:28:39 -07:00
parent 8dc1e859e0
commit 37cb9bcaa0
5 changed files with 28 additions and 19 deletions

View file

@ -1,11 +1,10 @@
// Eryn Wells <eryn@erynwells.me>
use crate::{
castle,
PieceSet, castle,
display::DiagramFormatter,
piece_sets::{PlacePieceError, PlacePieceStrategy},
zobrist::{ZobristHash, ZobristState},
PieceSet,
};
use chessfriend_bitboard::BitBoard;
use chessfriend_core::{Color, Piece, Shape, Square, Wing};
@ -109,11 +108,16 @@ impl Board {
#[must_use]
pub fn active_color_has_castling_right(&self, wing: Wing) -> bool {
self.color_has_castling_right(self.active_color, wing)
self.color_has_castling_right_unwrapped(self.active_color, wing)
}
#[must_use]
pub fn color_has_castling_right(&self, color: Color, wing: Wing) -> bool {
pub fn color_has_castling_right(&self, color: Option<Color>, wing: Wing) -> bool {
self.color_has_castling_right_unwrapped(self.unwrap_color(color), wing)
}
#[must_use]
pub fn color_has_castling_right_unwrapped(&self, color: Color, wing: Wing) -> bool {
self.castling_rights.color_has_right(color, wing)
}
@ -129,7 +133,12 @@ impl Board {
self.update_zobrist_hash_castling_rights(old_rights);
}
pub fn revoke_castling_right(&mut self, color: Color, wing: Wing) {
pub fn revoke_castling_right(&mut self, color: Option<Color>, wing: Wing) {
let color = self.unwrap_color(color);
self.revoke_castling_right_unwrapped(color, wing);
}
pub fn revoke_castling_right_unwrapped(&mut self, color: Color, wing: Wing) {
let old_rights = self.castling_rights;
self.castling_rights.revoke(color, wing);
self.update_zobrist_hash_castling_rights(old_rights);