Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions src/types/moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ impl Move {
Square::new(((self.0 >> 6) & 0b0011_1111) as u8)
}

pub const fn fromto(self) -> u16 {
self.0 & 0x0FFF
}

pub const fn kind(self) -> MoveKind {
unsafe { mem::transmute((self.0 >> 12) as u8) }
}
Expand Down Expand Up @@ -112,28 +116,10 @@ impl Move {
}

#[cfg(feature = "syzygy")]
pub const fn to_tb_move(self) -> crate::bindings::TbMove {
const fn promo_bits(pt: PieceType) -> crate::bindings::TbMove {
match pt {
PieceType::Queen => 1,
PieceType::Rook => 2,
PieceType::Bishop => 3,
PieceType::Knight => 4,
_ => unreachable!(),
}
}
pub fn to_tb_move(self) -> crate::bindings::TbMove {
let promo_pt = if self.is_promotion() { PieceType::King as u16 - self.promo_piece_type() as u16 } else { 0 };

let from = self.from() as u16;
let to = self.to() as u16;

let base = (from << 6) | to;

if self.is_promotion() {
let promo = promo_bits(self.promo_piece_type()) & 0x7;
base | (promo << 12)
} else {
base
}
self.fromto() | (promo_pt << 12)
}

pub fn to_uci(self, board: &Board) -> String {
Expand Down
Loading