added method uci_notation to struct BitMove

This commit is contained in:
Varga Dávid Lajos
2025-11-18 17:38:48 +01:00
parent fd0d26486b
commit db333a693f
2 changed files with 17 additions and 0 deletions

View File

@@ -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<u8> {
return self.promotion_piece;
}
pub fn uci_notation(&self) -> String {
let mut notation = notation_from_square_number(self.from_square());
notation.push_str(&notation_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)]

View File

@@ -48,6 +48,11 @@ pub fn try_get_square_number_from_notation(notation: &str) -> Result<u8, ()> {
}
}
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 ----->