WeightedDie
public struct WeightedDie
extension WeightedDie: Rollable
extension WeightedDie: Equatable
extension WeightedDie: Hashable
extension WeightedDie: Describable
A representation of a weighted die; i.e. a die whose sides do not necessarily have the same chance of being rolled.
The chances of specific rolls are passed using a Chances
object. It is recommended to create the object separately, because it is easier to manipulate the Chance
s that way.
Since
0.16.0-
Creates a new
WeightedDie
with the given rolls and chances of them occurring.Throws
Error.emptyDictionary
Parameters
c
The rolls and the chances of them occurring.
-
The number of possible
Roll
s.Declaration
Swift
public var sides: Int { get }
-
Creates a new
WeightedDie
that is a copy of the givenWeightedDie
.Declaration
Swift
@available(*, deprecated, message: "CustomDie is now a struct; copying is not necessary") public init(copyOf other: WeightedDie)
Parameters
other
The other
WeightedDie
to copy. -
The probabilities of all possible rolls.
Since
0.17.0Declaration
Swift
public var probabilities: Chances { get }
-
The exact (double) average result from using the
roll()
method.Declaration
Swift
public var doubleAverageResult: Double { get }
-
Determines whether this
WeightedDie
can reach the targetRoll
using the given comparison type.Since
0.15.0
Declaration
Swift
public func canReach(_ target: Roll, _ comparisonType: RollComparison) -> Bool
Parameters
target
The target to check reachibility for.
comparisonType
The comparison to use when checking reachibility.
Return Value
Whether or not this WeightedDie can reach the target, using the given comparison.
-
Declaration
Swift
public static func == (lhs: WeightedDie, rhs: WeightedDie) -> Bool
-
Declaration
Swift
public func hash(into hasher: inout Hasher)
-
Declaration
Swift
public var description: String { get }
-
Declaration
Swift
public var debugDescription: String { get }
-
Returns a copy of the given
WeightedDie
with separate memory.Declaration
Swift
@available(*, deprecated, message: "CustomDie is now a struct; copying is not necessary") func copy() -> WeightedDie
Return Value
A copy of the given
WeightedDie
, with the same number of sides, at a different memory location.