From 71950f3a0572e211d7cacb5a7f77b4e4e8efc5af Mon Sep 17 00:00:00 2001 From: ianagbip1oti Date: Sat, 13 Jan 2024 08:23:33 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Minor=20fixes=20and=20twe?= =?UTF-8?q?aks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chess/movegen.rs | 6 +++++- src/state.rs | 13 +++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/chess/movegen.rs b/src/chess/movegen.rs index 285f764..323967c 100644 --- a/src/chess/movegen.rs +++ b/src/chess/movegen.rs @@ -341,7 +341,11 @@ fn pawn_pushes(color: Color, from: Square, occ: Bitboard) -> Bitboard { pushes &= !occ; if pushes.any() && color.fold(from.rank() == Rank::_2, from.rank() == Rank::_7) { - let double = color.fold(from + 16, from - 16); + // fold is not appropriate here because it may overflow with the square maths + let double = match color { + Color::WHITE => from + 16, + Color::BLACK => from - 16, + }; pushes.toggle(double); pushes &= !occ; } diff --git a/src/state.rs b/src/state.rs index d65897d..27ff249 100644 --- a/src/state.rs +++ b/src/state.rs @@ -12,11 +12,7 @@ pub const NUMBER_FEATURES: usize = 768 * 3; #[derive(Clone)] pub struct State { board: Board, - - // 101 should be enough to track 50-move rule, but some games in the dataset - // can go above this. Hence we add a little space - prev_state_hashes: ArrayVec, - + prev_state_hashes: ArrayVec, prev_moves: [Option; 2], } @@ -105,18 +101,19 @@ impl State { if is_pawn_move || capture.is_some() { self.prev_state_hashes.clear(); + } else { + self.prev_state_hashes.push(self.hash()); } - self.prev_state_hashes.push(self.hash()); self.board.make_move(mov); } pub fn halfmove_counter(&self) -> usize { - self.prev_state_hashes.len() - 1 + self.prev_state_hashes.len() } pub fn drawn_by_fifty_move_rule(&self) -> bool { - self.prev_state_hashes.len() > 100 + self.prev_state_hashes.len() >= 100 } pub fn is_repetition(&self) -> bool {