1
0
Fork 0

Setup::validate -> Setup::into_position

This commit is contained in:
Paul-Nicolas Madelaine 2025-10-23 23:34:31 +02:00
parent 0d22c59cc3
commit 6f409799db
5 changed files with 19 additions and 18 deletions

View file

@ -10,7 +10,7 @@ use crate::position::*;
/// **A builder type for chess positions.**
///
/// This type is useful to edit a position without having to ensure it stays legal at every step.
/// It must be validated and converted to a [`Position`] using the [`Setup::validate`] method
/// It must be validated and converted to a [`Position`] using the [`Setup::into_position`] method
/// before generating moves.
///
/// This type implements [`FromStr`](std::str::FromStr) and [`Display`](std::fmt::Display) to parse
@ -245,10 +245,10 @@ impl Setup {
}
}
/// Tries to validate the position, i.e. converting it to a [`Position`].
/// Tries to convert the position into the [`Position`] type.
///
/// See [`IllegalPositionReason`] for details.
pub fn validate(self) -> Result<Position, IllegalPosition> {
/// Some unreachable positions are rejected, see [`IllegalPositionReason`] for details.
pub fn into_position(self) -> Result<Position, IllegalPosition> {
debug_assert!((self.w & !(self.p_b_q | self.n_b_k | self.r_q_k)).is_empty());
debug_assert!((self.p_b_q & self.n_b_k & self.r_q_k).is_empty());