Skip to content

Fix Dice.roll() ValueError for sides=0, matching ROM's dice() - #14

Merged
ctoth merged 1 commit into
masterfrom
fix/dice-roll-zero-sides
Jul 27, 2026
Merged

Fix Dice.roll() ValueError for sides=0, matching ROM's dice()#14
ctoth merged 1 commit into
masterfrom
fix/dice-roll-zero-sides

Conversation

@ctoth

@ctoth ctoth commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Fixes #8.

Dice.roll() raised ValueError: empty range in randrange(1, 1) for any dice with sides == 0, including a default-constructed Dice(). ROM's dice() (src/db.c) defines size 0 as rolling 0, so a 0-sided roll now returns just the bonus.

Negative sides (which also crashed) follow ROM's number_range(), which clamps a degenerate range to its low bound — 1 per die.

Verification

  • New tests test_dice_roll_zero_sides_contributes_zero and test_dice_roll_negative_sides_rolls_one_per_die failed with the issue's exact ValueError before the fix, pass after.
  • Full suite: 940 passed.
  • The issue's reproduction, run directly: Dice(number=2, sides=0, bonus=0).roll()0; Dice().roll()0; Dice(number=5, sides=0, bonus=7).roll()7.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HfQ678eD83tiAALqNkct1U

randrange(1, 1) is an empty range, so any Dice with sides == 0 --
including a default-constructed Dice() -- raised ValueError. ROM's
dice() (src/db.c) defines size 0 as rolling 0, so a 0-sided roll now
returns just the bonus. Negative sides follow ROM's number_range(),
which clamps a degenerate range to its low bound (1 per die).

Fixes #8

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HfQ678eD83tiAALqNkct1U
@ctoth
ctoth force-pushed the fix/dice-roll-zero-sides branch from a54c799 to 3be59a1 Compare July 27, 2026 00:45
@ctoth
ctoth merged commit f889d06 into master Jul 27, 2026
4 checks passed
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.

Dice.roll() raises ValueError for sides=0 where ROM's dice() returns 0

1 participant