diff --git a/engine/src/bitboard/bitmove.rs b/engine/src/bitboard/bitmove.rs index 0ec351b..86c5b44 100644 --- a/engine/src/bitboard/bitmove.rs +++ b/engine/src/bitboard/bitmove.rs @@ -1,3 +1,4 @@ +use super::utils::*; #[derive(Copy, Clone, PartialEq, Eq)] pub struct BitMove { @@ -54,6 +55,17 @@ impl BitMove { 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)] 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 ----->