diff --git a/engine/src/bitboard.rs b/engine/src/bitboard.rs index 504ae04..405141f 100644 --- a/engine/src/bitboard.rs +++ b/engine/src/bitboard.rs @@ -3,5 +3,6 @@ mod utils; mod legality; mod checkinfo; mod attacks; +mod bitmove; pub mod board; \ No newline at end of file diff --git a/engine/src/bitboard/bitmove.rs b/engine/src/bitboard/bitmove.rs new file mode 100644 index 0000000..86c5b44 --- /dev/null +++ b/engine/src/bitboard/bitmove.rs @@ -0,0 +1,77 @@ +use super::utils::*; + +#[derive(Copy, Clone, PartialEq, Eq)] +pub struct BitMove { + + move_type: BitMoveType, + from_square: u8, + to_square: u8, + promotion_piece: Option +} + +impl BitMove { + + #[inline] + pub fn quiet(from: u8, to: u8, promotion_piece: Option) -> Self { + return Self { + move_type: BitMoveType::Quiet, + from_square: from, + to_square: to, + promotion_piece: promotion_piece + }; + } + #[inline] + pub fn capture(from: u8, to: u8, promotion_piece: Option) -> Self { + return Self { + move_type: BitMoveType::Capture, + from_square: from, + to_square: to, + promotion_piece: promotion_piece + }; + } + #[inline] + pub fn castle(from: u8, to: u8) -> Self { + return Self { + move_type: BitMoveType::Castle, + from_square: from, + to_square: to, + promotion_piece: None + }; + } + + #[inline(always)] + pub fn move_type(&self) -> BitMoveType { + return self.move_type; + } + #[inline(always)] + pub fn from_square(&self) -> u8 { + return self.from_square; + } + #[inline(always)] + pub fn to_square(&self) -> u8 { + return self.to_square; + } + #[inline(always)] + pub fn promotion_piece(&self) -> Option { + return self.promotion_piece; + } + + pub fn uci_notation(&self) -> String { + let mut notation = notation_from_square_number(self.from_square()); + notation.push_str(¬ation_from_square_number(self.to_square())); + + if let Some(promotion_piece) = self.promotion_piece { + notation.push(get_character_by_piece_id(promotion_piece).to_ascii_lowercase()); + } + + return notation; + } +} + +#[derive(Copy, Clone, PartialEq, Eq)] +pub enum BitMoveType { + Quiet, + Capture, + Castle, + EnPassant +} \ No newline at end of file diff --git a/engine/src/bitboard/utils.rs b/engine/src/bitboard/utils.rs index 25d7ba8..f7f83fe 100644 --- a/engine/src/bitboard/utils.rs +++ b/engine/src/bitboard/utils.rs @@ -48,6 +48,11 @@ pub fn try_get_square_number_from_notation(notation: &str) -> Result { } } +const PIECE_CHARACTERS: [char; 12] = ['P', 'N', 'B', 'R', 'Q', 'K', 'p', 'n', 'b', 'r', 'q', 'k']; +pub fn get_character_by_piece_id(id: u8) -> char { + return PIECE_CHARACTERS[id as usize]; +} + // <----- TESTS ----->