Skip to content

Add checked BitBoard::to_maybe_square(); document to_square() on empty (#91)#92

Open
Booyaka101 wants to merge 1 commit into
jordanbray:mainfrom
Booyaka101:fix/91-bitboard-to-maybe-square
Open

Add checked BitBoard::to_maybe_square(); document to_square() on empty (#91)#92
Booyaka101 wants to merge 1 commit into
jordanbray:mainfrom
Booyaka101:fix/91-bitboard-to-maybe-square

Conversation

@Booyaka101

Copy link
Copy Markdown

Addresses #91.

On current main, BitBoard::new(0).to_square() returns A1, not the invalid a9 from the report — Square::new already masks with & 63, so the out-of-range square is gone. What remains is that to_square() silently returns A1 for an empty BitBoard, which is indistinguishable from a BitBoard with only A1 set.

This adds BitBoard::to_maybe_square() -> Option<Square>, the checked counterpart of to_square() (mirroring the existing from_maybe_square), returning None when the BitBoard is empty. to_square()'s documentation now states its non-empty precondition and points to the checked method.

Additive and non-breaking. Doctests on both methods serve as tests; the full suite (36 unit + 142 doc) passes. to_maybe_square takes &self to match the existing to_square/to_size convention.

On current main, BitBoard::new(0).to_square() returns A1, not the invalid
"a9" from the report -- Square::new already masks with & 63. What remains is
that to_square() silently returns A1 for an empty BitBoard, which is
indistinguishable from a BitBoard with only A1 set.

Add BitBoard::to_maybe_square() -> Option<Square>, the checked counterpart of
to_square() (mirroring the existing from_maybe_square), returning None when
empty. to_square()'s documentation now states its non-empty precondition and
points to the checked method.

Additive and non-breaking. to_maybe_square uses &self to match the existing
to_square/to_size convention.

Addresses jordanbray#91.
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

Successfully merging this pull request may close these issues.

1 participant