jordanbray / chess

A rust library to manage chess move generation
https://jordanbray.github.io/chess/
MIT License
231 stars 54 forks source link

Move generation is unsound for non-standard positions #55

Open analog-hors opened 3 years ago

analog-hors commented 3 years ago
fn main() {
    chess::MoveGen::new_legal(&"3k4/8/PPPPPPPP/8/PPPPPPPP/8/PPPPPPPP/3K4 w - - 0 1".parse().unwrap());
}

leads to

thread 'main' panicked at 'assertion failed: len < A::CAPACITY', C:\Users\analog_hors\.cargo\registry\src\github.com-1ecc6299db9ec823\arrayvec-0.5.2\src\lib.rs:265:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\chess-test.exe` (exit code: 101)

on debug mode. Compiling for release disables the assertion and causes undefined behavior instead. Should probably either prevent non-standard boards from getting created (which sounds tricky since I doubt this is the only way to get one) or account for this during move generation.

jordanbray commented 1 year ago

Yeah. It should not be possible to create positions with more than 16 pieces.