Skip to content

Commit

Permalink
🐛 FIX: Minor fixes and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ianagbip1oti committed Jan 13, 2024
1 parent 97379ec commit 71950f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/chess/movegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 5 additions & 8 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64, 128>,

prev_state_hashes: ArrayVec<u64, 100>,
prev_moves: [Option<Move>; 2],
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 71950f3

Please sign in to comment.