update docs
This commit is contained in:
parent
671ff331d3
commit
b45952b6b7
5 changed files with 47 additions and 43 deletions
30
src/setup.rs
30
src/setup.rs
|
|
@ -12,8 +12,8 @@ use alloc::string::String;
|
|||
/// **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::into_position`] method
|
||||
/// before generating moves.
|
||||
/// It must be validated and converted to a [`Position`] using [`Setup::into_position`] before
|
||||
/// generating moves.
|
||||
///
|
||||
/// ## Text description
|
||||
///
|
||||
|
|
@ -21,8 +21,12 @@ use alloc::string::String;
|
|||
/// uses a slightly different notation, which simply removes the last two fields of the FEN record
|
||||
/// (i.e. the halfmove clock and the fullmove number) as the [`Position`] type does not keep
|
||||
/// track of those. For example, the starting position is recorded as
|
||||
/// `rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -`. [`Setup::from_text_record`] and
|
||||
/// [`Setup::to_text_record`] can be used to read and write these records.
|
||||
/// `rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -`.
|
||||
///
|
||||
/// [`Display`](core::fmt::Display) and [`FromStr`](alloc::str::FromStr) are purposely not
|
||||
/// implemented on [`Setup`] as there does not exist a truely canonical format for writing chess
|
||||
/// positions. The format described above is implemented in
|
||||
/// [`from_text_record`](Setup::from_text_record) and [`to_text_record`](Setup::to_text_record).
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Setup {
|
||||
pub(crate) w: Bitboard,
|
||||
|
|
@ -51,21 +55,14 @@ impl Setup {
|
|||
}
|
||||
}
|
||||
|
||||
/// Reads a position from a text record.
|
||||
///
|
||||
/// This is a shortcut for:
|
||||
/// ```
|
||||
/// # use eschac::setup::Setup;
|
||||
/// # |record: &str| {
|
||||
/// Setup::from_ascii_record(record.as_bytes())
|
||||
/// # };
|
||||
/// ```
|
||||
/// Reads a position from a text record
|
||||
/// (see [`from_ascii_record`](Setup::from_ascii_record)).
|
||||
#[inline]
|
||||
pub fn from_text_record(record: &str) -> Result<Self, ParseRecordError> {
|
||||
Self::from_ascii_record(record.as_bytes())
|
||||
}
|
||||
|
||||
/// Reads a position from an ascii record.
|
||||
/// Reads a position from a text record.
|
||||
pub fn from_ascii_record(record: &[u8]) -> Result<Self, ParseRecordError> {
|
||||
let mut s = record.iter().copied().peekable();
|
||||
let mut setup = Setup::new();
|
||||
|
|
@ -146,7 +143,8 @@ impl Setup {
|
|||
})
|
||||
}
|
||||
|
||||
/// Returns the text record of the position.
|
||||
/// Returns the text record of the position
|
||||
/// (see [`write_text_record`](Setup::write_text_record)).
|
||||
pub fn to_text_record(&self) -> String {
|
||||
let mut record = String::with_capacity(81);
|
||||
self.write_text_record(&mut record).unwrap();
|
||||
|
|
@ -614,7 +612,7 @@ impl Iterator for IllegalPositionReasons {
|
|||
}
|
||||
}
|
||||
|
||||
/// Reasons for illegal positions to be rejected by eschac.
|
||||
/// Reasons for an illegal position to be rejected by eschac.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
pub enum IllegalPositionReason {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue