UnMove

Struct UnMove 

Source
pub struct UnMove {
    pub from: Square,
    pub to: Square,
    /* private fields */
}
Expand description

Information about a move.

Called UnMove not to be confused with shakmaty::Move. When there is no doubt about which one is reffered to, can be called “move”.

Fields§

§from: Square§to: Square

Implementations§

Source§

impl UnMove

Source

pub fn from_retro_uci(retro_uci: &str) -> Result<UnMove, ParseRetroUciError>

movements are represented with uci, but for uncapture and unpromote a special syntax is used:

-Uncapture: the piece left at the source square is indicated at the beginning, follow by normal uci move. e.g: “Re2e4” the piece on e2 goes on e4 and leaves a Rook from the opposite color on e2.

-Unpromotion: “U” and after the square from which the piece will underpromote and the source square must be on the 8th or 1st rank, and dest square must be on first or second rank. e.g: “Ue8e7”. An unpromotion can also be an uncapture, in this case it’s noted “U<from_square><to_square>” e.g “UNe8e7”

-En passant: “E” then the source square of the pawn and the destination of it. When a move is en-passsant, it cannot Uncapture anything (since the pawn uncapture is already implied) e.g “Ed6e5”. Note than it’s different than “Pd6e5”. In the first example, the uncaptured pawn is in d5, while in the second one it’s in d6.

regex: r“[UE]?[NBRQ]?([abcdefgh][1-8]){2}“

Note: A unmove being accepted does not means it is for sure legal, just syntaxically correct

§Examples
use retroboard::UnMove;
use shakmaty::{Square, Role};

let simple_move: UnMove = UnMove::from_retro_uci("Pe2e4").unwrap();
assert_eq!(simple_move.from, Square::E2);
assert_eq!(simple_move.to, Square::E4);
assert_eq!(simple_move.uncapture(), Some(Role::Pawn));

let unpromotion: UnMove = UnMove::from_retro_uci("Ue8e7").unwrap();
assert_eq!(unpromotion.from, Square::E8);
assert_eq!(unpromotion.to, Square::E7);
assert!(unpromotion.is_unpromotion());
assert!(!unpromotion.is_en_passant());

let en_passant: UnMove = UnMove::from_retro_uci("Ee3d4").unwrap();
assert_eq!(en_passant.from, Square::E3);
assert_eq!(en_passant.to, Square::D4);
assert!(en_passant.is_en_passant());
assert!(!en_passant.is_unpromotion());
Source

pub fn new(from: Square, to: Square, move_kind: MoveKind) -> Self

Retuns a new UnMove.

Source

pub fn to_retro_uci(&self) -> String

Returns a string following the retro uci standard. See UnMove::from_retro_uci for more information.

Source

pub fn is_uncapture(&self) -> bool

Source

pub fn uncapture(&self) -> Option<Role>

Source

pub fn is_unpromotion(&self) -> bool

Source

pub fn is_en_passant(&self) -> bool

Source

pub fn uncapture_square(&self) -> Option<Square>

If the move is an uncapture moves, returns the square when the piece uncaptured will land. It is always the from square, except for en-passant move.

§Examples
use retroboard::UnMove;
use shakmaty::Square;

assert_eq!(
    UnMove::from_retro_uci("Ed3e4")
        .unwrap()
        .uncapture_square()
        .unwrap(),
    Square::D4,
);
assert_eq!(
    UnMove::from_retro_uci("Qa8h1")
        .unwrap()
        .uncapture_square()
        .unwrap(),
    Square::A8,
);
Source

pub fn mirror(&self) -> Self

Map the from and to attribute vertically. Represent the same move if player’s color were swapped

§Examples
use retroboard::UnMove;

assert_eq!(
    UnMove::from_retro_uci("Ua1a2").unwrap().mirror(),
    UnMove::from_retro_uci("Ua8a7").unwrap()
);

Trait Implementations§

Source§

impl Clone for UnMove

Source§

fn clone(&self) -> UnMove

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UnMove

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for UnMove

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for UnMove

Source§

fn eq(&self, other: &UnMove) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for UnMove

Source§

impl StructuralPartialEq for UnMove

Auto Trait Implementations§

§

impl Freeze for UnMove

§

impl RefUnwindSafe for UnMove

§

impl Send for UnMove

§

impl Sync for UnMove

§

impl Unpin for UnMove

§

impl UnwindSafe for UnMove

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.