aboutsummaryrefslogtreecommitdiff
path: root/src/board.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/board.rs')
-rw-r--r--src/board.rs27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/board.rs b/src/board.rs
index 241412e..b76356f 100644
--- a/src/board.rs
+++ b/src/board.rs
@@ -3,6 +3,9 @@ use crate::bitboard::Bitboard;
#[derive(Debug)]
pub struct Board {
pub pieces: [Bitboard; 12],
+
+ pub occupancy: Bitboard,
+ pub ply: u16,
}
@@ -80,7 +83,21 @@ impl Board {
}
}
- Self { pieces }
+ let mut board = Self { pieces, occupancy: 0, ply: 0 };
+ board.update_occupancy();
+ board
+ }
+
+ fn update_occupancy(&mut self) {
+ self.occupancy = 0;
+ // TODO: reduce
+ for piece in self.pieces {
+ self.occupancy |= piece;
+ }
+ }
+
+ fn empty(&self) -> Bitboard {
+ !self.occupancy
}
pub fn print(&self) {
@@ -130,7 +147,7 @@ pub enum Square {
#[cfg(test)]
mod tests {
use super::*;
- use crate::bitboard::{pop_count, bitscan};
+ use crate::bitboard::{pop_count, bitscan, print};
#[test]
fn test_square_enum() {
@@ -144,6 +161,9 @@ mod tests {
let fen = String::from("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
let board = Board::from_FEN(fen);
+ board.print();
+ print(board.empty(), "Empty squares");
+
assert_eq!(pop_count(board.pieces[PieceTypes::Pawn as usize]), 8);
assert_eq!(pop_count(board.pieces[PieceTypes::Knight as usize]), 2);
assert_eq!(pop_count(board.pieces[PieceTypes::Bishop as usize]), 2);
@@ -161,6 +181,7 @@ mod tests {
assert_eq!(bitscan(board.pieces[PieceTypes::King as usize]), Square::E1 as u8);
assert_eq!(bitscan(board.pieces[PieceTypes::QueenBlack as usize]), Square::D8 as u8);
- board.print();
+ assert_eq!(pop_count(board.occupancy), 32);
+ assert_eq!(pop_count(board.empty()), 32);
}
}