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

Question in next of impl Iterator for MoveGen #88

Closed
miguel-ambrona opened this issue May 26, 2024 · 1 comment
Closed

Question in next of impl Iterator for MoveGen #88

miguel-ambrona opened this issue May 26, 2024 · 1 comment

Comments

@miguel-ambrona
Copy link

miguel-ambrona commented May 26, 2024

I'm puzzled by this first case:
https://github.com/jordanbray/chess/blob/main/src/movegen/movegen.rs#L302-L306

    fn next(&mut self) -> Option<ChessMove> {
        if self.index >= self.moves.len()
            || self.moves[self.index].bitboard & self.iterator_mask == EMPTY
        {
            // are we done?
            None

Shouldn't we increase self.index before returning None?

@miguel-ambrona
Copy link
Author

Ok, I guess this works without increasing self.index because of two properties:

  • All self.moves have a non-empty .bitboard (at least initially).
  • Function set_iterator_mask does some magic: it sorts the moves in such a way that the ones with remaining destinies always go first.

I would then rephrase the above comment: // are we done? -> // we are done, or just remove it. It confused me a little.

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