Module: GamesDice

Defined in:
lib/games_dice.rb,
lib/games_dice/version.rb,
lib/games_dice/constants.rb

Defined Under Namespace

Classes: Bunch, ComplexDie, Dice, Die, DieResult, MapRule, Parser, Probabilities, RerollRule

Constant Summary collapse

VERSION =
"0.3.10"
REROLL_TYPES =

Reasons for making a reroll, and text explanation symbols for them

{
  :basic => ',',
  :reroll_add => '+',
  :reroll_subtract => '-',
  :reroll_replace => '|',
  :reroll_use_best => '/',
  :reroll_use_worst => '\\',
  # These are not yet implemented:
  # :reroll_new_die => '*',
  # :reroll_new_keeper => '*',
}

Class Method Summary collapse

Class Method Details

.create(dice_description, prng = nil) ⇒ GamesDice::Dice

Creates an instance of GamesDice::Dice from a string description.

Parameters:

  • dice_description (String)

    Uses a variation of common game notation, examples: ‘1d6’, ‘3d8+1d4+7’, ‘5d10k2’

  • prng (#rand) (defaults to: nil)

    Optional random number generator, default is to use Ruby’s built-in #rand()

Returns:



27
28
29
30
# File 'lib/games_dice.rb', line 27

def self.create dice_description, prng = nil
  parsed = @@parser.parse( dice_description )
  GamesDice::Dice.new( parsed[:bunches], parsed[:offset], prng )
end