Skip to content

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

@analog-hors

Description

@analog-hors

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:

// the iterator portion of this struct relies on the invariant that
// the bitboards at the beginning of the moves[] array are the only
// ones used. As a result, we must partition the list such that the
// assumption is true.

This leads to the iterator methods ending early.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions