[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

@ -46,7 +46,7 @@ impl Board {
let color = self.unwrap_color(color);
if !self.color_has_castling_right(color, wing) {
if !self.color_has_castling_right_unwrapped(color, wing) {
return Err(CastleEvaluationError::NoRights { color, wing });
}
@ -94,7 +94,7 @@ impl Board {
mod tests {
use super::*;
use crate::test_board;
use chessfriend_core::{piece, Color, Wing};
use chessfriend_core::{Color, Wing, piece};
#[test]
fn king_on_starting_square_can_castle() {
@ -104,8 +104,8 @@ mod tests {
White Rook on H1
);
assert!(board.color_has_castling_right(Color::White, Wing::KingSide));
assert!(board.color_has_castling_right(Color::White, Wing::QueenSide));
assert!(board.color_has_castling_right_unwrapped(Color::White, Wing::KingSide));
assert!(board.color_has_castling_right_unwrapped(Color::White, Wing::QueenSide));
}
#[test]