CustomDie

public struct CustomDie<Output> where Output : Hashable
extension CustomDie: Equatable
extension CustomDie: Hashable
extension CustomDie: Describable

A class that allows for dice with custom sides instead of numbers.

This class wraps a Die instance, and when roll() is called on this, it calls the Die’s roll() method and maps the output to one of the DieSides passed to the initializer.

Since

0.16.0

Author

Samasaur
  • A dictionary that maps the rolls of the die to the DieSides passed to the initializer

    Declaration

    Swift

    public private(set) var sides: [Roll : DieSide<Output>] { get }
  • Creates a new CustomDie, replacing one side with a new one.

    Declaration

    Swift

    public func replacing(_ side: DieSide<Output>, with newSide: DieSide<Output>) -> CustomDie<Output>

    Parameters

    side

    The side to replace.

    newSide

    The side to replace it with.

    Return Value

    A new CustomDie, after the first side has been replaced with the second.

  • Creates a new CustomDie with the given sides.

    Throws

    An Error.IllegalNumberOfSides error when the number of sides is less than or equal to 0

    Declaration

    Swift

    public init(_ sides: DieSide<Output>...) throws

    Parameters

    sides

    The sides of the die.

  • Creates a new CustomDie with the given sides.

    Throws

    An Error.IllegalNumberOfSides error when the number of sides is less than or equal to 0

    Declaration

    Swift

    public init(sides sidesArr: [DieSide<Output>]) throws

    Parameters

    sidesArr

    The sides of the die.

  • Creates a new CustomDie that is a copy of the given CustomDie.

    Declaration

    Swift

    @available(*, deprecated, message: "CustomDie is now a struct; copying is not necessary")
    public init(copyOf other: CustomDie)

    Parameters

    other

    The other CustomDie to copy.

  • Rolls this CustomDie.

    Declaration

    Swift

    func roll() -> DieSide<Output>

    Return Value

    One of the DieSides passed to the initializer.

  • Determined the chance of rolling the given DieSide.

    Since

    0.17.0

    Declaration

    Swift

    func chance(of roll: DieSide<Output>) -> Chance

    Parameters

    roll

    The DieSide to check the chance of rolling.

    Return Value

    The chance of rolling the given DieSide.

  • Declaration

    Swift

    public static func == (lhs: CustomDie, rhs: CustomDie) -> 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 CustomDie with separate memory.

    Declaration

    Swift

    @available(*, deprecated, message: "CustomDie is now a struct; copying is not necessary")
    func copy() -> CustomDie

    Return Value

    A copy of the given CustomDie, with the same number of sides and DieSides, at a different memory location.