pub struct Move(/* private fields */);Expand description
Represents a move on the chessboard.
Move is a u64 number. It contains 3 types of information:
-
Information about the played move itself.
-
Information needed so as to be able to undo the move and restore the board into the exact same state as before.
-
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
impl Move
Sourcepub 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
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.
Sourcepub fn invalid() -> Move
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.
Sourcepub fn piece_from_aux_data(pp_code: usize) -> PieceType
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.
Sourcepub fn played_piece(&self) -> PieceType
pub fn played_piece(&self) -> PieceType
Returns the played piece type.
Castling is considered as king’s move.
Sourcepub fn orig_square(&self) -> Square
pub fn orig_square(&self) -> Square
Returns the origin square of the played piece.
Sourcepub fn dest_square(&self) -> Square
pub fn dest_square(&self) -> Square
Returns the destination square for the played piece.
Sourcepub fn captured_piece(&self) -> PieceType
pub fn captured_piece(&self) -> PieceType
Returns the captured piece type.
Sourcepub fn enpassant_file(&self) -> usize
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.
Sourcepub fn castling_rights(&self) -> CastlingRights
pub fn castling_rights(&self) -> CastlingRights
Returns the castling rights as they were before the move was played.
Sourcepub fn aux_data(&self) -> usize
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.
Sourcepub fn digest(&self) -> MoveDigest
pub fn digest(&self) -> MoveDigest
Returns the least significant 16 bits of the raw move value.
Sourcepub fn notation(&self) -> String
pub fn notation(&self) -> String
Returns the algebraic notation of the move.
Examples: e2e4, e7e5, e1g1 (white short castling),
e7e8q (for promotion).
Sourcepub fn is_pawn_advance_or_capure(&self) -> bool
pub fn is_pawn_advance_or_capure(&self) -> bool
Returns true if the move is a pawn advance or a capture,
false otherwise.
Sourcepub fn is_null(&self) -> bool
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.