Enum pgn_reader::San
source · pub enum San {
Normal {
role: Role,
file: Option<File>,
rank: Option<Rank>,
capture: bool,
to: Square,
promotion: Option<Role>,
},
Castle(CastlingSide),
Put {
role: Role,
to: Square,
},
Null,
}
Expand description
A move in Standard Algebraic Notation.
Variants§
Implementations§
source§impl San
impl San
sourcepub fn from_ascii(san: &[u8]) -> Result<San, ParseSanError>
pub fn from_ascii(san: &[u8]) -> Result<San, ParseSanError>
Parses a SAN. Ignores a possible check or checkmate suffix.
Errors
Returns ParseSanError
if san
is not syntactically valid.
sourcepub fn from_move<P>(pos: &P, m: &Move) -> Sanwhere
P: Position,
pub fn from_move<P>(pos: &P, m: &Move) -> Sanwhere
P: Position,
Converts a move to Standard Algebraic Notation.
pub fn disambiguate(m: &Move, moves: &ArrayVec<Move, _>) -> San
sourcepub fn matches(&self, m: &Move) -> bool
pub fn matches(&self, m: &Move) -> bool
Test if the San
can match the Move
(in any position).
Examples
use shakmaty::{Square, Role, Move, san::San};
let m = Move::Normal {
role: Role::Knight,
from: Square::G1,
to: Square::F3,
capture: None,
promotion: None,
};
let nf3 = San::from_ascii(b"Nf3")?;
assert!(nf3.matches(&m));
let ng1f3 = San::from_ascii(b"Ng1f3")?;
assert!(ng1f3.matches(&m));
// capture does not match
let nxf3 = San::from_ascii(b"Nxf3")?;
assert!(!nxf3.matches(&m));
// other file does not match
let nef3 = San::from_ascii(b"Nef3")?;
assert!(!nef3.matches(&m));