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 Chances that way.

Since

0.16.0

Author

Samasaur
  • The rolls and the chances of them occurring.

    Declaration

    Swift

    public let chances: [Roll : Chance]
  • Creates a new WeightedDie with the given rolls and chances of them occurring.

    Declaration

    Swift

    public init(chances c: Chances) throws

    Parameters

    c

    The rolls and the chances of them occurring.

  • The number of possible Rolls.

    Declaration

    Swift

    public var sides: Int { get }
  • Creates a new WeightedDie that is a copy of the given WeightedDie.

    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.0

    Declaration

    Swift

    public var probabilities: Chances { get }
  • Rolls this WeightedDie and returns the result as a Roll.

    Declaration

    Swift

    public func roll() -> Roll

    Return Value

    One of the possible Rolls as given in the initializer, proportionally likely as given there.

  • The minimum possible result from using the roll() method.

    Declaration

    Swift

    public var minimumResult: Roll { get }
  • The maximum possible result from using the roll() method.

    Declaration

    Swift

    public var maximumResult: Roll { get }
  • The exact (double) average result from using the roll() method.

    Declaration

    Swift

    public var doubleAverageResult: Double { get }
  • The average result from using the roll() method.

    Declaration

    Swift

    public var averageResult: Roll { get }
  • Determines whether this WeightedDie can reach the target Roll 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.