Add TT lookups in quiescence, move TT inside Game, remove redundant occupancy and time limit functions

This commit is contained in:
stefiosif
2025-01-18 13:01:06 +02:00
parent e9729cf95d
commit 824f8a37b5
9 changed files with 70 additions and 119 deletions

View File

@@ -22,7 +22,7 @@ pub struct Board {
}
impl Board {
pub const fn new() -> Self {
pub const fn startpos() -> Self {
Self {
pieces: [
0xff00000000ff00,
@@ -37,7 +37,7 @@ impl Board {
}
}
pub const fn empty_board() -> Self {
pub const fn new_empty() -> Self {
Self {
pieces: [0x0, 0x0, 0x0, 0x0, 0x0, 0x0],
color: [0x0, 0x0],
@@ -45,20 +45,8 @@ impl Board {
}
}
fn white_occupancies(&self) -> Bitboard {
self.color[Color::White]
}
fn black_occupancies(&self) -> Bitboard {
self.color[Color::Black]
}
pub fn all_occupancies(&self) -> Bitboard {
self.white_occupancies() | self.black_occupancies()
}
pub fn is_attacked(&self, square: usize, opponent_color: Color) -> bool {
let all_occupancies = self.all_occupancies();
let all_occupancies = self.color[Color::White] | self.color[Color::Black];
let own_color = opponent_color.opponent();
let opponent_color_bb = &self.color[opponent_color];
@@ -108,7 +96,7 @@ impl Board {
}
pub fn pseudo_moves(&self, color: Color, piece_type: PieceType) -> Vec<Move> {
let all_occupancies = self.all_occupancies();
let all_occupancies = self.color[Color::White] | self.color[Color::Black];
let pieces = self.pieces[piece_type] & self.color[color];
let own_occupancies = self.color[color];
let opponent_occupancies = self.color[color.opponent()];
@@ -186,7 +174,7 @@ impl Board {
impl Default for Board {
fn default() -> Self {
Self::new()
Self::new_empty()
}
}
@@ -277,9 +265,12 @@ mod tests {
fn test_occupancies() -> Result<(), String> {
let new_game = from_fen(FEN_EXAMPLE[0])?;
assert_eq!(new_game.board.white_occupancies(), 0x40000002000000);
assert_eq!(new_game.board.black_occupancies(), 0x900204401002);
assert_eq!(new_game.board.all_occupancies(), 0x40900206401002);
assert_eq!(new_game.board.color[Color::White], 0x40000002000000);
assert_eq!(new_game.board.color[Color::Black], 0x900204401002);
assert_eq!(
new_game.board.color[Color::White] | new_game.board.color[Color::Black],
0x40900206401002
);
Ok(())
}