jordanbray / chess

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

Question in `next` of `impl Iterator for MoveGen` #88

Closed miguel-ambrona closed 1 month ago

miguel-ambrona commented 1 month ago

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 commented 1 month ago

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