Implement redundant mailbox representation

This commit is contained in:
stefiosif
2024-09-19 22:57:03 +03:00
parent 3739e6e169
commit f74f1ef364
11 changed files with 252 additions and 132 deletions

View File

@@ -164,30 +164,6 @@ impl Board {
self.state = state;
}
pub fn piece_type_at_color(&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)
}
pub fn piece_type_at(&self, square: usize) -> Option<PieceType> {
if let Some(at_white) = self.piece_type_at_color(square, Color::White) {
return Some(at_white);
}
if let Some(at_black) = self.piece_type_at_color(square, Color::Black) {
return Some(at_black);
}
None
}
pub fn update_game_state(
state: &mut State,
mv: &Move,
@@ -212,6 +188,10 @@ impl Board {
p.bitboard &= !square_to_bitboard(src);
p.bitboard |= square_to_bitboard(dst);
});
//TODO:
// pieces[piece_type].bitboard &= !square_to_bitboard(src);
// pieces[piece_type].bitboard |= square_to_bitboard(dst);
}
pub fn remove_own_piece(&mut self, square: usize) {
@@ -234,16 +214,6 @@ impl Board {
});
}
pub fn move_rook_castle(&mut self, king_dst: usize) {
let (rook_src, rook_dst) = match king_dst {
Square::C1 | Square::C8 => (king_dst - 2, king_dst + 1),
Square::G1 | Square::G8 => (king_dst + 1, king_dst - 1),
_ => return,
};
self.move_piece(rook_src, rook_dst);
}
pub fn promote_piece(&mut self, square: usize, promote: &Promote) {
let pieces = self.own_pieces();
match promote {
@@ -254,15 +224,6 @@ impl Board {
};
}
pub fn remove_pawn_enpassant(&mut self, square: usize, color: Color) {
let piece_to_remove = match color {
Color::White => square - 8,
Color::Black => square + 8,
};
self.remove_opponent_piece(piece_to_remove);
}
pub fn is_pawn_move(&mut self, square: usize) -> bool {
let pieces = self.own_pieces();
have_common_bit(square_to_bitboard(square), pieces[PieceType::Pawn].bitboard)
@@ -331,7 +292,6 @@ impl PieceType {
use std::ops::{Index, IndexMut};
use super::bitboard::square_to_bitboard;
use super::square::Square;
impl Index<PieceType> for [Piece] {
type Output = Piece;
@@ -365,7 +325,7 @@ impl Color {
#[cfg(test)]
mod tests {
use crate::{
board::fen::from_fen,
board::{fen::from_fen, square::Square},
movegen::{attack_generator::init_attacks, r#move::MoveType},
};