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
impl Move
const FROM_MASK: u16 = 63u16
const PROMOTION_MASK: u16 = 28_672u16
const PROMOTION_OFFSET: u8 = 12u8
const TO_MASK: u16 = 4_032u16
const TO_OFFSET: u8 = 6u8
pub fn new(from: Square, to: Square, promotion: Option<Promotion>) -> Self
pub(super) fn from(&self) -> Square
pub(super) fn to(&self) -> Square
pub(super) fn promotion(&self) -> Option<Promotion>
sourcepub fn from_uci(uci: &str) -> Result<Self>
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.
sourcepub fn flip_perspective(&self) -> Self
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)
);
pub(super) fn as_packed_int(&self) -> u16
Trait Implementations§
source§impl PartialEq for Move
impl PartialEq for Move
impl Copy for Move
impl Eq for Move
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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