[board, explorer, moves] Clean up the castling rights API

Reorganize castling rights API on Board into methods named according to
conventions applied to other API.

Board::has_castling_right
Board::has_castling_right_active
Board::has_castling_right_unwrapped

    These all check if a color has the right to castle on a particular side
    (wing) of the board. The first takes an Option<Color>, the latter two
    operate on bare Colors: the active color, or an explicit Color.

Board::grant_castling_right
Board::grant_castling_right_active
Board::grant_castling_right_unwrapped

    Grant castling rights to a color. Color arguments follow the pattern above.

Board::revoke_castling_right
Board::revoke_castling_right_active
Board::revoke_castling_right_unwrapped

    Revoke castling rights from a color. Color arguments follow the pattern
    above.

The latter two groups of methods take a new CastleRightsOption type that
specifies either a single Wing or All.

Rework the implementation of CastleRights to take a CastleRightsOption. Update
the unit tests and make sure everything builds.
This commit is contained in:
Eryn Wells 2025-06-18 23:44:40 +00:00
parent 933924d37a
commit 4ce7e89cdb
8 changed files with 177 additions and 124 deletions

View file

@ -1,16 +1,11 @@
// Eryn Wells <eryn@erynwells.me>
use chessfriend_board::castle::CastleEvaluationError;
use chessfriend_board::{Board, fen::FromFenStr};
use chessfriend_board::{CastleParameters, ZobristState};
use chessfriend_core::random::RandomNumberGenerator;
use chessfriend_core::{Color, Piece, Shape, Square, Wing};
use chessfriend_moves::algebraic::AlgebraicMoveComponents;
use chessfriend_moves::{GeneratedMove, ValidateMove};
use chessfriend_board::{Board, ZobristState, fen::FromFenStr};
use chessfriend_core::{Color, Piece, Shape, Square, Wing, random::RandomNumberGenerator};
use chessfriend_moves::{GeneratedMove, ValidateMove, algebraic::AlgebraicMoveComponents};
use chessfriend_position::{PlacePieceStrategy, Position, fen::ToFenStr};
use clap::{Arg, Command, value_parser};
use rustyline::DefaultEditor;
use rustyline::error::ReadlineError;
use rustyline::{DefaultEditor, error::ReadlineError};
use std::sync::Arc;
use thiserror::Error;
@ -202,7 +197,7 @@ fn do_flags_command(state: &mut State, _matches: &clap::ArgMatches) -> CommandRe
(Color::Black, Wing::KingSide),
(Color::Black, Wing::QueenSide),
] {
let has_right = board.color_has_castling_right_unwrapped(color, wing);
let has_right = board.has_castling_right_unwrapped(color, wing.into());
let can_castle = board.color_can_castle(wing, Some(color));
let can_castle_message = match can_castle {