text records
This commit is contained in:
parent
0e65b4f927
commit
bbe65b74f4
6 changed files with 173 additions and 167 deletions
|
|
@ -65,7 +65,7 @@ const MAX_LEGAL_MOVES: usize = 218;
|
|||
impl std::fmt::Debug for Position {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
f.debug_tuple("Position")
|
||||
.field(&self.as_setup().to_string())
|
||||
.field(&self.as_setup().to_text_record())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
@ -96,12 +96,26 @@ impl Position {
|
|||
/// ```
|
||||
/// # use eschac::setup::Setup;
|
||||
/// # |s: &str| -> Option<eschac::position::Position> {
|
||||
/// s.parse::<Setup>().ok().and_then(|pos| pos.validate().ok())
|
||||
/// Setup::from_text_record(s).ok().and_then(|pos| pos.validate().ok())
|
||||
/// # };
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn from_text_record(s: &str) -> Option<Self> {
|
||||
s.parse::<Setup>().ok().and_then(|pos| pos.validate().ok())
|
||||
Setup::from_text_record(s)
|
||||
.ok()
|
||||
.and_then(|pos| pos.validate().ok())
|
||||
}
|
||||
|
||||
/// Returns the text record of the position.
|
||||
///
|
||||
/// This is a shortcut for:
|
||||
/// ```
|
||||
/// # |position: eschac::position::Position| {
|
||||
/// position.as_setup().to_text_record()
|
||||
/// # };
|
||||
#[inline]
|
||||
pub fn to_text_record(&self) -> String {
|
||||
self.as_setup().to_text_record()
|
||||
}
|
||||
|
||||
/// Returns all the legal moves on the position.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue