aboutsummaryrefslogtreecommitdiff
path: root/src/board
diff options
context:
space:
mode:
Diffstat (limited to 'src/board')
-rw-r--r--src/board/io.rs1
-rw-r--r--src/board/mod.rs12
2 files changed, 10 insertions, 3 deletions
diff --git a/src/board/io.rs b/src/board/io.rs
index d27b856..15d7744 100644
--- a/src/board/io.rs
+++ b/src/board/io.rs
@@ -97,6 +97,7 @@ impl IO for Board {
castling_rights: [[true; 2]; 2], // TODO: actualy parse from FEN
ep_target: None, // TODO: parse from FEN
clock: Clock::default(),
+ positions: Vec::new(),
hash: 0,
zobrist_seed: Board::seed(),
};
diff --git a/src/board/mod.rs b/src/board/mod.rs
index 95d470a..50aa1b9 100644
--- a/src/board/mod.rs
+++ b/src/board/mod.rs
@@ -15,7 +15,7 @@ pub enum CastlingSide {
/// Chess board is an main interface to the internal game state.
/// Board defines rules of the game and manages players actions.
-#[derive(Debug, Clone, Copy, PartialEq)]
+#[derive(Debug, Clone, PartialEq)]
pub struct Board {
pub ply: u16,
pub piece_sets: [Bitboard; 12],
@@ -26,12 +26,16 @@ pub struct Board {
pub clock: Clock,
+ /// List of all positions to determine repetitions
+ pub positions: Vec<u64>,
+
// Computed values
pub occupancy: Bitboard,
/// Zobrist hash of the current position
pub hash: u64,
zobrist_seed: ZobristSeed,
+
pub attacks: Attacks,
}
@@ -227,6 +231,7 @@ impl Board {
self.ply += 1;
self.zobrist_toggle_color();
+ self.positions.push(self.hash);
captured_piece
}
@@ -320,6 +325,7 @@ impl Board {
self.castling_rights = previous_castling_rights;
self.hash = previous_hash;
self.ply -= 1;
+ self.positions.pop();
}
pub fn is_square_attacked(&self, square: Square, attacker_color: Color) -> bool {
@@ -388,7 +394,7 @@ mod tests {
fn make_move() {
let fen = String::from("q1b2k2/5p1p/4p1pb/pPPp4/3N4/3nPB2/P2QKnR1/1R6 w - - 0 25");
let mut board = Board::from_FEN(fen);
- let initial_board = board;
+ let initial_board = board.clone();
board.print();
let black_move = Move { source: Square::F7, target: Square::F5, kind: MoveKind::Quiet };
@@ -429,7 +435,7 @@ mod tests {
fn unmake_move() {
let fen = String::from("q1b2k2/5p1p/4p1pb/pPPp4/3N4/3nPB2/P2QKnR1/1R6 w - - 0 25");
let mut board = Board::from_FEN(fen);
- let initial_board = board;
+ let initial_board = board.clone();
let mov = Move { source: Square::D2, target: Square::A5, kind: MoveKind::Capture };