jordanbray / chess

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

`remove_move` and `remove_mask` truncate moves in the move generator. #66

Open analog-hors opened 2 years ago

analog-hors commented 2 years ago

remove_move and remove_mask truncate moves in the move generator:

fn main() {
    let board = "8/8/5k2/8/3Pp3/8/2K5/8 b - d3 0 1".parse().unwrap();
    let mut moves = chess::MoveGen::new_legal(&board);
    let len = moves.len();
    moves.remove_move("e4e3".parse().unwrap());
    assert_eq!(moves.len(), len - 1); //Assertion fails with 0 != 8
}
fn main() {
    let board = "8/8/5k2/8/3Pp3/8/2K5/8 b - d3 0 1".parse().unwrap();
    let mut moves = chess::MoveGen::new_legal(&board);
    let len = moves.len();
    moves.remove_mask(chess::BitBoard::from_square(chess::Square::E3));
    assert_eq!(moves.len(), len - 1); //Assertion fails with 0 != 8
}

This is because remove_move and remove_mask fail to uphold the invariant where no non-empty SquareAndBitBoards may come after an empty one. This invariant is mentioned here: https://github.com/jordanbray/chess/blob/ad138579074ca1b0a88514626016d8e0b72d4ed3/src/movegen/movegen.rs#L157-L160 This leads to the iterator methods ending early.