added specialized getter method get_piece_character to bitboard/board.rs

This commit is contained in:
Varga Dávid Lajos
2025-11-27 22:18:04 +02:00
parent b5c18419d8
commit 24ddc74573

View File

@@ -196,4 +196,46 @@ impl Board {
_ => () _ => ()
} }
} }
pub fn get_piece_character(&self, index: i32) -> Option<char> {
let sq = 1 << index;
if (self.bitboards[0] & sq) != 0 {
return Some('P');
}
if (self.bitboards[1] & sq) != 0 {
return Some('N');
}
if (self.bitboards[2] & sq) != 0 {
return Some('B');
}
if (self.bitboards[3] & sq) != 0 {
return Some('R');
}
if (self.bitboards[4] & sq) != 0 {
return Some('Q');
}
if (self.bitboards[5] & sq) != 0 {
return Some('K');
}
if (self.bitboards[6] & sq) != 0 {
return Some('p');
}
if (self.bitboards[7] & sq) != 0 {
return Some('n');
}
if (self.bitboards[8] & sq) != 0 {
return Some('b');
}
if (self.bitboards[9] & sq) != 0 {
return Some('r');
}
if (self.bitboards[10] & sq) != 0 {
return Some('q');
}
if (self.bitboards[11] & sq) != 0 {
return Some('k');
}
return None;
}
} }