Skip to content

Commit 9fa1943

Browse files
committed
fix: load fen fix
1 parent e0511df commit 9fa1943

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/board/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Board {
104104
fifty_move_ply_count: 0,
105105
current_zobrist: 0,
106106
},
107-
ply: 0,
107+
ply: 1,
108108
moves: Vec::new(),
109109
zobrist_history: Vec::new(),
110110
fen_history: Vec::new(),
@@ -180,6 +180,7 @@ impl Board {
180180
_ => panic!("Invalid FEN"),
181181
};
182182

183+
self.game_state.castling_rights = 0;
183184
if parts[2].contains('K') {
184185
self.game_state.castling_rights |= CASTLING_WHITE_KING;
185186
}
@@ -269,13 +270,14 @@ impl Board {
269270
} + if is_king_side { 0 } else { 1 };
270271

271272
let mask = 1 << index;
272-
let king_square = CASTLING_RIGHTS_SQUARES[index][0];
273-
let rook_square = CASTLING_ROOKS[index];
274273

275274
if self.game_state.castling_rights & mask == 0 {
276275
return false;
277276
}
278277

278+
let king_square = CASTLING_RIGHTS_SQUARES[index][0];
279+
let rook_square = CASTLING_ROOKS[index];
280+
279281
self.is_empty_between(king_square, rook_square)
280282
}
281283

tests/board_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ mod tests {
1818
let mut board = Board::new();
1919
board.reset();
2020
assert_eq!(board.turn, Color::White);
21-
assert_eq!(board.halfmove_clock, 0);
22-
assert_eq!(board.fullmove_number, 1);
21+
assert_eq!(board.game_state.fifty_move_ply_count, 0);
22+
assert_eq!(board.ply, 0);
2323
assert!(board
2424
.pieces
2525
.iter()
@@ -31,7 +31,7 @@ mod tests {
3131
let mut board = Board::new();
3232
board.set_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
3333
assert_eq!(board.turn, Color::White);
34-
assert_eq!(board.fullmove_number, 1);
34+
assert_eq!(board.ply, 0);
3535
assert!(board.pieces[Color::White as usize][Piece::Pawn as usize].is_set(8));
3636
assert!(board.pieces[Color::Black as usize][Piece::Pawn as usize].is_set(48));
3737
}
@@ -211,12 +211,12 @@ mod tests {
211211

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

214-
assert_eq!(board.castling_rights, 0b1111);
214+
assert_eq!(board.game_state.castling_rights, 0b1111);
215215

216-
assert_eq!(board.en_passant_square, None);
216+
assert_eq!(board.game_state.en_passant_square, None);
217217

218-
assert_eq!(board.halfmove_clock, 0);
219-
assert_eq!(board.fullmove_number, 1);
218+
assert_eq!(board.game_state.fifty_move_ply_count, 0);
219+
assert_eq!(board.ply, 0);
220220
}
221221

222222
#[test]

0 commit comments

Comments
 (0)