Struct pabi::chess::core::Move

source ·
pub struct Move(u16);
Expand description

Represents any kind of a legal chess move. A move is the only way to mutate crate::chess::position::Position and change the board state. Moves are not sorted according to their potential “value” by the move generator. The move representation has one-to-one correspondence with the UCI move representation. The moves can also be indexed and fed as an input to the Neural Network evaluators that would be able assess their potential without evaluating post-states.

Tuple Fields§

§0: u16

Implementations§

source§

impl Move

source

const FROM_MASK: u16 = 63u16

source

const PROMOTION_MASK: u16 = 28_672u16

source

const PROMOTION_OFFSET: u8 = 12u8

source

const TO_MASK: u16 = 4_032u16

source

const TO_OFFSET: u8 = 6u8

source

pub fn new(from: Square, to: Square, promotion: Option<Promotion>) -> Self

source

pub(super) fn from(&self) -> Square

source

pub(super) fn to(&self) -> Square

source

pub(super) fn promotion(&self) -> Option<Promotion>

source

pub fn from_uci(uci: &str) -> Result<Self>

Converts the move from UCI format to the internal representation. This is important for the communication between the engine and UCI server in position command.

source

pub fn flip_perspective(&self) -> Self

Converts the move from the perspective of one player to the other, as if the other player’s backrank is rank 1.

This is very useful for encoding the moves to reduce the action space and pass them as actions to the policy network.

§Example
use pabi::chess::core::{Move, Square};

assert_eq!(
    Move::new(Square::E1, Square::E8, None).flip_perspective(),
    Move::new(Square::E8, Square::E1, None)
);
source

pub(super) fn as_packed_int(&self) -> u16

Trait Implementations§

source§

impl Action for Move

source§

fn get_index(&self) -> u16

source§

impl Clone for Move

source§

fn clone(&self) -> Move

Returns a copy 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 Move

source§

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

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

impl Display for Move

source§

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

Serializes a move in UCI format (used by [pabi::uci]).

source§

impl Environment<Move, Position> for Game

source§

fn actions(&self) -> &[Move]

source§

fn apply(&mut self, action: &Move) -> &Position

source§

fn result(&self) -> Option<GameResult>

source§

impl PartialEq for Move

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<&str> for Move

§

type Error = Error

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

fn try_from(uci: &str) -> Result<Self>

Performs the conversion.
source§

impl Copy for Move

source§

impl Eq for Move

source§

impl StructuralPartialEq for Move

Auto Trait Implementations§

§

impl Freeze for Move

§

impl RefUnwindSafe for Move

§

impl Send for Move

§

impl Sync for Move

§

impl Unpin for Move

§

impl UnwindSafe for Move

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.