Add utility functions for readability and refactor make_move

This commit is contained in:
stefiosif
2024-08-28 21:07:22 +03:00
parent 6c8f445fa9
commit 21076da68c
10 changed files with 91 additions and 61 deletions

View File

@@ -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;