Module pleco::core::piece_move[][src]

Module for the implementation and definition of a move to be played.

We define a move as the struct BitMove. A move needs 16 bits to be stored, and they are used as such:

bits  0 - 5:  destination square (from 0 to 63)
bits  6 - 11: origin square (from 0 to 63)
bits 12 - 13: promotion piece type - 2 (from KNIGHT-0 to QUEEN-4)
bits 14 - 15: special move flag: promotion (1), en passant (2), castling (3)

Special cases

Special cases are MOVE_NONE and MOVE_NULL. We can sneak these in because in any normal move destination square is always different from origin square while MOVE_NONE and MOVE_NULL have the same origin and destination square.

Another special case is where the move is a castling move. If the move is a castle, then the corresponding flags will be set and the origin square will be the square of the king, while the destination square will be the square of the rook to castle with.

Lastly, the En-passant flag is only set if the move is a pawn double-push.

Bit Flags for a BitMove

The flags for a move are set as such:

x??? --> Promotion bit
?x?? --> Capture bit
??xx --> flag Bit

More specifically, the flags correspond to the following bit patterns:

0000  ===> Quiet move
0001  ===> Double Pawn Push
0010  ===> King Castle
0011  ===> Queen Castle
0100  ===> Capture
0101  ===> EP Capture
0110  ===>
0111  ===>
1000  ===> Knight Promotion
1001  ===> Bishop Promo
1010  ===> Rook   Promo
1011  ===> Queen  Capture  Promo
1100  ===> Knight Capture  Promotion
1101  ===> Bishop Capture  Promo
1110  ===> Rook   Capture  Promo
1111  ===> Queen  Capture  Promo

Safety

A BitMove is only guaranteed to be legal for a specific position. If a Board generates a list of moves, then only those moves are correct. It is not recommended to use BitMoves on a Board that didn't directly create them, unless it is otherwise known that move correlates to that specific board position.

Structs

BitMove

Represents a singular move.

PreMoveInfo

Useful pre-encoding of a move's information before it is compressed into a BitMove struct.

ScoringMove

A move that stores a score as well

Enums

MoveFlag

Selected Meta-Data to accompany each move.

MoveType

A Subset of MoveFlag, used to determine the overall classification of a move.