Skip to content

Comments

Fix index out of bounds panic in iterative_parallel_mvv_lva when depth >= 10#168

Merged
chase-manning merged 2 commits intomainfrom
copilot/fix-iterative-parallel-mvv-lva-panic
Feb 22, 2026
Merged

Fix index out of bounds panic in iterative_parallel_mvv_lva when depth >= 10#168
chase-manning merged 2 commits intomainfrom
copilot/fix-iterative-parallel-mvv-lva-panic

Conversation

Copy link
Contributor

Copilot AI commented Feb 22, 2026

IterativeSearcher::best_move panics when called with depth >= 10 because the iterative deepening loop indexes into PLYS_SEQ (length 10) with the raw depth value, which goes out of bounds.

index out of bounds: the len is 10 but the index is 10
  • Clamp the PLYS_SEQ index to the last valid entry so depths beyond the table size use the plateau value (3)
  • Add regression test with the exact FEN from the bug report
// Before
let returned_b_move = jamboree(&mut b, alpha, beta, i, PLYS_SEQ[i as usize]);

// After
let plys_idx = std::cmp::min(i as usize, PLYS_SEQ.len() - 1);
let returned_b_move = jamboree(&mut b, alpha, beta, i, PLYS_SEQ[plys_idx]);
Original prompt

This section details on the original issue you should resolve

<issue_title>iterative_parallel_mvv_lva panic</issue_title>
<issue_description>```rust
use pleco::{bots::IterativeSearcher, tools::Searcher, Board};

fn main() {
let mut clipboard = arboard::Clipboard::new().unwrap();
let mut last_clipboard_text = "".to_string();
loop {
let current_clipboard_text = clipboard.get_text().unwrap();
if current_clipboard_text.starts_with("FEN: ") {
if current_clipboard_text != last_clipboard_text {
let fen = current_clipboard_text[5..].trim();
let board = Board::from_fen(&fen).unwrap();
let depth = 10;
println!("Searching depth {depth} for FEN: {fen}");
let best_move = IterativeSearcher::best_move(board, depth);
println!("FEN: {fen} Best move: {}", best_move);
last_clipboard_text = current_clipboard_text.clone();
}
}
std::thread::sleep(std::time::Duration::from_millis(100));
}
}


$ cargo run
Compiling chess_bot v0.1.0 (/Users/brandon/Desktop/chess_bot)
Finished dev profile [unoptimized + debuginfo] target(s) in 0.21s
Running /Users/brandon/.cargo/target/debug/chess_bot
Searching depth 10 for FEN: 1k6/R7/8/7B/7P/8/5Q2/B3K2R w K - 11 47
thread 'main' panicked at /Users/brandon/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pleco-0.5.0/src/bots/iterative_parallel_mvv_lva.rs:39:64:
index out of bounds: the len is 10 but the index is 10
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace


## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…h >= 10

Clamp PLYS_SEQ index to the maximum valid array index so that depths
exceeding the array length use the last entry instead of panicking.

Co-authored-by: chase-manning <53957795+chase-manning@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic in iterative parallel mvv lva handling Fix index out of bounds panic in iterative_parallel_mvv_lva when depth >= 10 Feb 22, 2026
Copilot AI requested a review from chase-manning February 22, 2026 12:31
@chase-manning chase-manning marked this pull request as ready for review February 22, 2026 23:33
@chase-manning chase-manning merged commit f54c0c2 into main Feb 22, 2026
4 checks passed
@chase-manning chase-manning deleted the copilot/fix-iterative-parallel-mvv-lva-panic branch February 22, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iterative_parallel_mvv_lva panic

2 participants