Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
analog-hors opened this issue Sep 10, 2021 · 0 comments
Open

Comments

@analog-hors
Copy link

analog-hors commented Sep 10, 2021

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.

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

No branches or pull requests

1 participant