Move

Struct Move 

Source
pub struct Move(/* private fields */);
Expand description

Represents a move on the chessboard.

Move is a u64 number. It contains 3 types of information:

  1. Information about the played move itself.

  2. Information needed so as to be able to undo the move and restore the board into the exact same state as before.

  3. Move ordering info – moves with higher move score are tried first.

Bits 0-15 contain the whole information about the move itself. This is called “move digest” and is laid out the following way:

 15                                                           0
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
| Move  |    Origin square      |   Destination square  | Aux   |
| type  |       6 bits          |        6 bits         | data  |
| 2 bits|   |   |   |   |   |   |   |   |   |   |   |   | 2 bits|
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

There are 4 “move type“s: 0) en-passant capture; 1) pawn promotion; 2) castling; 3) normal move. “Aux data” encodes the type of the promoted piece if the move type is pawn promotion, otherwise it is zero.

Bits 16-31 contain the information needed to undo the move:

 31                                                          16
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
|   |   |  Captured |  Played   |   Castling    |   En-passant  |
| 0 | 0 |  piece    |  piece    |    rights     |      file     |
|   |   |  3 bits   |  3 bits   |    4 bits     |     4 bits    |
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

If the previous move was a double pawn push, “en-passant file” contains pushed pawn’s file (a value between 0 and 7). Otherwise it contains 8. “Castling rights” holds the castling rights before the move was played. When “Captured piece” is stored, its bits are inverted, so that MVV-LVA (Most valuable victim – least valuable aggressor) move ordering is followed for moves that have the same “score”.

Bits 32-63 contain the “score” field, which is used to influence move ordering.

Implementations§

Source§

impl Move

Source

pub fn new( move_type: MoveType, orig_square: Square, dest_square: Square, aux_data: usize, captured_piece: PieceType, played_piece: PieceType, castling_rights: CastlingRights, enpassant_file: usize, score: u32, ) -> Move

Creates a new instance.

Source

pub fn invalid() -> Move

Creates an invalid move instance.

The returned instance tries to mimic a legal move, but its move digest equals MoveDigest::invalid(). This is sometimes useful in places where any move is required but no is available.

Source

pub fn piece_from_aux_data(pp_code: usize) -> PieceType

Decodes the promoted piece type from the raw value returned by aux_data.

The interpretation of the raw value is: 0 – queen, 1 – rook, 2 – bishop, 3 – knight.

Source

pub fn set_score(&mut self, score: u32)

Assigns a new score for the move.

Source

pub fn score(&self) -> u32

Returns the assigned move score.

Source

pub fn move_type(&self) -> MoveType

Returns the move type.

Source

pub fn played_piece(&self) -> PieceType

Returns the played piece type.

Castling is considered as king’s move.

Source

pub fn orig_square(&self) -> Square

Returns the origin square of the played piece.

Source

pub fn dest_square(&self) -> Square

Returns the destination square for the played piece.

Source

pub fn captured_piece(&self) -> PieceType

Returns the captured piece type.

Source

pub fn enpassant_file(&self) -> usize

If the previous move was a double pawn push, returns pushed pawn’s file (a value between 0 and 7). Otherwise returns 8.

Source

pub fn castling_rights(&self) -> CastlingRights

Returns the castling rights as they were before the move was played.

Source

pub fn aux_data(&self) -> usize

Returns a value between 0 and 3 representing the auxiliary data.

When the move type is pawn promotion, “aux data” encodes the promoted piece type. For all other move types “aux data” is zero.

Source

pub fn digest(&self) -> MoveDigest

Returns the least significant 16 bits of the raw move value.

Source

pub fn notation(&self) -> String

Returns the algebraic notation of the move.

Examples: e2e4, e7e5, e1g1 (white short castling), e7e8q (for promotion).

Source

pub fn is_pawn_advance_or_capure(&self) -> bool

Returns true if the move is a pawn advance or a capture, false otherwise.

Source

pub fn is_null(&self) -> bool

Returns if the move is a null move.

“Null move” is a pseudo-move that changes nothing on the board except the side to move. It is sometimes useful to include a speculative null move in the search tree to achieve more aggressive pruning. Null moves are represented as king’s moves for which the origin and destination squares are the same.

Trait Implementations§

Source§

impl Clone for Move

Source§

fn clone(&self) -> Move

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

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

impl Ord for Move

Source§

fn cmp(&self, other: &Move) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Move

Source§

fn eq(&self, other: &Move) -> 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 PartialOrd for Move

Source§

fn partial_cmp(&self, other: &Move) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
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> 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> ToString for T
where T: Display + ?Sized,

Source§

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

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.