Add utility functions for readability and refactor make_move
This commit is contained in:
@@ -167,6 +167,18 @@ impl Board {
|
||||
pub fn set_state(&mut self, state: State) {
|
||||
self.state = state;
|
||||
}
|
||||
|
||||
pub fn piece_type_at(&self, square: usize, color: Color) -> Option<PieceType> {
|
||||
let pieces = match color {
|
||||
Color::White => &self.white_pieces,
|
||||
Color::Black => &self.black_pieces,
|
||||
};
|
||||
|
||||
pieces
|
||||
.iter()
|
||||
.find(|p| have_common_bit(p.bitboard, square_to_bitboard(square)))
|
||||
.map(|p| p.piece_type)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Board {
|
||||
@@ -216,6 +228,8 @@ impl PieceType {
|
||||
}
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
use super::bitboard::square_to_bitboard;
|
||||
|
||||
impl Index<PieceType> for [Piece] {
|
||||
type Output = Piece;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user