class Rollable::Dice
- Rollable::Dice
- Rollable::IsRollable
- Reference
- Object
Overview
Not a front class. It is used to represent a tuple of die type and die amount
A Dice
is a amount of Die
.
It is rollable exactly like a classic Die
It is also possible to get the details of a roll, using the methods
.min_details
, .max_details
, .average_details
, .test_details
Example:
d = Dice.parse "2d6"
d.min # => 2
d.max # => 12
d.average # => 7
d.min_details # => [1, 1]
d.test # => the sum of 2 random values between 1..6
Defined in:
rollable/dice.crrollable/dice/parse_wrap.cr
Constant Summary
-
MAX =
1000
Constructors
-
.new(count : Int32, die_type : Int32, exploding : Bool = false, drop : Int32 = 0)
Create a
Dice
with "die_type" faces. - .new(count : Int32, die : Rollable::Die, drop : Int32 = 0)
-
.parse(str : String, strict = true) : Dice
Returns the
Dice
parsed.
Class Method Summary
-
.consume(str : String, &) : String | Nil
Returns the unconsumed string.
-
.parse(str : String, strict = true, &) : String
Return a valid string parsed from
str
.
Instance Method Summary
- #<(right : Dice)
- #<=(right : Dice)
- #<=>(right : Dice) : Int32
- #==(right : Dice)
- #>(right : Dice)
- #>=(right : Dice)
- #average : Float64
- #average_details : Array(Float64)
- #clone
- #count : Int32
- #count=(count : Int32)
- #count_after_drop
- #die : Rollable::Die
- #drop : Int32
- #fixed?(*args, **options)
- #fixed?(*args, **options, &)
- #max : Int32
- #max_details : Array(Int32)
- #min : Int32
- #min_details : Array(Int32)
- #negative?(*args, **options)
- #negative?(*args, **options, &)
- #reverse : Dice
- #reverse!
-
#test : Int32
Roll an amount of
Dice
as specified, and return the sum -
#test_details : Array(Int32)
Roll an amount of
Dice
as specified, and return the values -
#test_details_with_drop : Tuple(Array(Int32), Array(Int32))
Roll an amount of
Dice
as specified, and return the values along with the values that would be dropped -
#to_s : String
Return a string which represents the
Dice
Instance methods inherited from class Rollable::IsRollable
average : Float64
average,
max : Int32
max,
min : Int32
min,
test : Int32
test
Constructor Detail
Create a Dice
with "die_type" faces.
Returns the Dice
parsed. (see #parse_string
)
Class Method Detail
Returns the unconsumed string.
Parse str
, and yield a Dice
parsed.
It does not requires to be a full valid string
(see #parse when strict is false).
rest = Dice.consume("1d6+2") do |dice|
# dice = Dice.new(1, Die.new(1..6))
end
# rest = "+2"
Return a valid string parsed from str
. (see #parse_string
)
Yields the Dice
parsed from str
.
Then, it returns the string read.
If strict is false, only the valid string is returned.
Dice.parse("1d6") {|dice| dice.roll } => "1d6"
Instance Method Detail
Roll an amount of Dice
as specified, and return the values along with the
values that would be dropped