Skip to content

Commit

Permalink
fix: load fen fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacperacy committed Jan 18, 2025
1 parent e0511df commit 9fa1943
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/board/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Board {
fifty_move_ply_count: 0,
current_zobrist: 0,
},
ply: 0,
ply: 1,
moves: Vec::new(),
zobrist_history: Vec::new(),
fen_history: Vec::new(),
Expand Down Expand Up @@ -180,6 +180,7 @@ impl Board {
_ => panic!("Invalid FEN"),
};

self.game_state.castling_rights = 0;
if parts[2].contains('K') {
self.game_state.castling_rights |= CASTLING_WHITE_KING;
}
Expand Down Expand Up @@ -269,13 +270,14 @@ impl Board {
} + if is_king_side { 0 } else { 1 };

let mask = 1 << index;
let king_square = CASTLING_RIGHTS_SQUARES[index][0];
let rook_square = CASTLING_ROOKS[index];

if self.game_state.castling_rights & mask == 0 {
return false;
}

let king_square = CASTLING_RIGHTS_SQUARES[index][0];
let rook_square = CASTLING_ROOKS[index];

self.is_empty_between(king_square, rook_square)
}

Expand Down
14 changes: 7 additions & 7 deletions tests/board_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ mod tests {
let mut board = Board::new();
board.reset();
assert_eq!(board.turn, Color::White);
assert_eq!(board.halfmove_clock, 0);
assert_eq!(board.fullmove_number, 1);
assert_eq!(board.game_state.fifty_move_ply_count, 0);
assert_eq!(board.ply, 0);
assert!(board
.pieces
.iter()
Expand All @@ -31,7 +31,7 @@ mod tests {
let mut board = Board::new();
board.set_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
assert_eq!(board.turn, Color::White);
assert_eq!(board.fullmove_number, 1);
assert_eq!(board.ply, 0);
assert!(board.pieces[Color::White as usize][Piece::Pawn as usize].is_set(8));
assert!(board.pieces[Color::Black as usize][Piece::Pawn as usize].is_set(48));
}
Expand Down Expand Up @@ -211,12 +211,12 @@ mod tests {

assert_eq!(board.turn, Color::White);

assert_eq!(board.castling_rights, 0b1111);
assert_eq!(board.game_state.castling_rights, 0b1111);

assert_eq!(board.en_passant_square, None);
assert_eq!(board.game_state.en_passant_square, None);

assert_eq!(board.halfmove_clock, 0);
assert_eq!(board.fullmove_number, 1);
assert_eq!(board.game_state.fifty_move_ply_count, 0);
assert_eq!(board.ply, 0);
}

#[test]
Expand Down

0 comments on commit 9fa1943

Please sign in to comment.