Skip to content

Commit f54c0c2

Browse files
Merge pull request #168 from pleco-rs/copilot/fix-iterative-parallel-mvv-lva-panic
Fix index out of bounds panic in iterative_parallel_mvv_lva when depth >= 10
2 parents 9dc3255 + 18aa363 commit f54c0c2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pleco/src/bots/iterative_parallel_mvv_lva.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ pub fn iterative_deepening(board: &mut Board, max_depth: u16) -> BitMove {
3535
// clone the board
3636
let mut b = board.shallow_clone();
3737

38-
let returned_b_move = jamboree(&mut b, alpha, beta, i, PLYS_SEQ[i as usize]);
38+
let plys_idx = std::cmp::min(i as usize, PLYS_SEQ.len() - 1);
39+
let returned_b_move = jamboree(&mut b, alpha, beta, i, PLYS_SEQ[plys_idx]);
3940
if i >= 2 {
4041
if returned_b_move.score > beta {
4142
beta = INF_V;

pleco/src/bots/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,11 @@ mod tests {
142142
JamboreeSearcher::best_move(b2, 5)
143143
);
144144
}
145+
146+
#[test]
147+
fn iterative_searcher_depth_10() {
148+
let b = Board::from_fen("1k6/R7/8/7B/7P/8/5Q2/B3K2R w K - 11 47").unwrap();
149+
// Should not panic with depth >= PLYS_SEQ length
150+
let _best = IterativeSearcher::best_move(b, 10);
151+
}
145152
}

0 commit comments

Comments
 (0)