pub enum Uci {
Normal {
from: Square,
to: Square,
promotion: Option<Role>,
},
Put {
role: Role,
to: Square,
},
Null,
}
Expand description
A move as represented in the UCI protocol.
Variants
Normal
A normal move, e.g. e2e4
or h2h1q
.
Put
A piece drop, e.g. Q@f7
.
Null
A null move (0000
).
Implementations
sourceimpl Uci
impl Uci
sourcepub fn from_ascii(uci: &[u8]) -> Result<Uci, ParseUciError>
pub fn from_ascii(uci: &[u8]) -> Result<Uci, ParseUciError>
Parses a move in UCI notation.
Errors
Returns ParseUciError
if uci
is not syntactically valid.
Examples
use shakmaty::{Square, uci::Uci};
let uci = Uci::from_ascii(b"e4e5")?;
assert_eq!(uci, Uci::Normal {
from: Square::E4,
to: Square::E5,
promotion: None,
});
sourcepub fn from_standard(m: &Move) -> Uci
pub fn from_standard(m: &Move) -> Uci
Converts a move to UCI notation. Castling moves are represented as a move of the king to its new position.
Warning: Using standard notation for castling moves in Chess960 may create moves that are illegal or moves that can be confused with king moves.
Examples
use shakmaty::{Move, Square, uci::Uci};
let m = Move::Castle {
king: Square::E8,
rook: Square::H8,
};
let uci = Uci::from_standard(&m);
assert_eq!(uci.to_string(), "e8g8");
sourcepub fn from_chess960(m: &Move) -> Uci
pub fn from_chess960(m: &Move) -> Uci
Converts a move to UCI notation. Castling moves are represented as a move of the king to the corresponding rook square, independently of the position.
Examples
use shakmaty::{Move, Square, uci::Uci};
let m = Move::Castle {
king: Square::E8,
rook: Square::H8,
};
let uci = Uci::from_chess960(&m);
assert_eq!(uci.to_string(), "e8h8");
sourcepub fn from_move(m: &Move, mode: CastlingMode) -> Uci
pub fn from_move(m: &Move, mode: CastlingMode) -> Uci
sourcepub fn to_move<P: Position>(&self, pos: &P) -> Result<Move, IllegalUciError>
pub fn to_move<P: Position>(&self, pos: &P) -> Result<Move, IllegalUciError>
Tries to convert the Uci
to a legal Move
in the context of a
position.
Errors
Returns IllegalUciError
if the move is not legal.
Trait Implementations
sourceimpl FromStr for Uci
impl FromStr for Uci
type Err = ParseUciError
type Err = ParseUciError
The associated error which can be returned from parsing.
impl Eq for Uci
impl StructuralEq for Uci
impl StructuralPartialEq for Uci
Auto Trait Implementations
impl RefUnwindSafe for Uci
impl Send for Uci
impl Sync for Uci
impl Unpin for Uci
impl UnwindSafe for Uci
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more