Add State struct as part of Board struct
This commit is contained in:
25
src/board.rs
25
src/board.rs
@@ -5,11 +5,13 @@ use crate::attack::{
|
||||
get_bishop_attacks, get_king_attacks, get_knight_attacks, get_pawn_attacks, get_queen_attacks,
|
||||
get_rook_attacks,
|
||||
};
|
||||
use crate::game::State;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct Board {
|
||||
white_pieces: [Piece; 6],
|
||||
black_pieces: [Piece; 6],
|
||||
pub white_pieces: [Piece; 6],
|
||||
pub black_pieces: [Piece; 6],
|
||||
pub state: State,
|
||||
}
|
||||
|
||||
impl Board {
|
||||
@@ -31,6 +33,7 @@ impl Board {
|
||||
Piece::new(0x800000000000000, Kind::Queen, Color::Black),
|
||||
Piece::new(0x1000000000000000, Kind::King, Color::Black),
|
||||
],
|
||||
state: State::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +55,7 @@ impl Board {
|
||||
Piece::new(0x0, Kind::Queen, Color::Black),
|
||||
Piece::new(0x0, Kind::King, Color::Black),
|
||||
],
|
||||
state: State::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,11 +66,20 @@ impl Board {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn get_all_occupancies(&self) -> Bitboard {
|
||||
let white_blockers = self.white_pieces.iter().fold(0, |acc, p| p.bitboard | acc);
|
||||
let black_blockers = self.black_pieces.iter().fold(0, |acc, p| p.bitboard | acc);
|
||||
pub fn set_state(&mut self, state: State) {
|
||||
self.state = state;
|
||||
}
|
||||
|
||||
white_blockers | black_blockers
|
||||
pub fn get_white_occupancies(&self) -> Bitboard {
|
||||
self.white_pieces.iter().fold(0, |acc, p| p.bitboard | acc)
|
||||
}
|
||||
|
||||
pub fn get_black_occupancies(&self) -> Bitboard {
|
||||
self.black_pieces.iter().fold(0, |acc, p| p.bitboard | acc)
|
||||
}
|
||||
|
||||
pub fn get_all_occupancies(&self) -> Bitboard {
|
||||
self.get_white_occupancies() | self.get_black_occupancies()
|
||||
}
|
||||
|
||||
pub fn is_attacked(&self, sq: usize, opponent_color: Color) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user