Class Dice

java.lang.Object
net.royalur.model.dice.Dice
Direct Known Subclasses:
BinaryDice

public abstract class Dice extends Object
A generator of dice rolls, that is _not_ necessarily thread-safe.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiates this dice with the given ID.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    copyFrom(Dice other)
    Copies the state of other into this dice.
    abstract Roll
    generateRoll(int value)
    Generates a roll with value value using this dice.
    Gets the type of this dice.
    Gets the ID of this dice type.
    abstract int
    Gets the maximum value that could be rolled by this dice.
    Gets the name of this dice.
    abstract float[]
    Gets the probability of rolling each value of the dice, where the index into the returned array represents the value of the roll.
    boolean
    Gets whether this dice has an associated dice type.
    boolean
    Returns whether this dice holds any state that affects its dice rolls.
    void
    recordRoll(int value)
    Updates the state of this dice after having rolled value.
    Generates a random roll using this dice.
    roll(int value)
    Generates a roll with value value using this dice.
    abstract int
    Generates a random roll using this dice, and returns just the value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Dice

      public Dice(String id)
      Instantiates this dice with the given ID.
  • Method Details

    • getID

      public String getID()
      Gets the ID of this dice type.
      Returns:
      The ID of this dice type.
    • hasDiceType

      public boolean hasDiceType()
      Gets whether this dice has an associated dice type. Custom dice may not have an associated dice type.
      Returns:
      Whether this dice has an associated dice type.
    • getDiceType

      public DiceType getDiceType()
      Gets the type of this dice.
      Returns:
      The type of this dice.
    • getName

      public String getName()
      Gets the name of this dice.
      Returns:
      The name of this dice.
    • hasState

      public boolean hasState()
      Returns whether this dice holds any state that affects its dice rolls. If this is overridden, then copyFrom(Dice) should also be overriden.
      Returns:
      Whether this dice holds any state that affects its dice rolls.
    • copyFrom

      public void copyFrom(Dice other)
      Copies the state of other into this dice. If the dice does not have state, this is a no-op. The state copied does _not_ include the seeding of the random number generator. If this is overriden, then hasState() should also be overriden.
      Parameters:
      other - The dice to copy the state from.
    • getMaxRollValue

      public abstract int getMaxRollValue()
      Gets the maximum value that could be rolled by this dice.
      Returns:
      The maximum value that this dice could possibly roll.
    • getRollProbabilities

      public abstract float[] getRollProbabilities()
      Gets the probability of rolling each value of the dice, where the index into the returned array represents the value of the roll.
      Returns:
      The probability of rolling each value of the dice.
    • rollValue

      public abstract int rollValue()
      Generates a random roll using this dice, and returns just the value. If this dice has state, this should call recordRoll(int).
      Returns:
      A random roll of this dice, and returns just the value.
    • recordRoll

      public void recordRoll(int value)
      Updates the state of this dice after having rolled value.
      Parameters:
      value - The value that was rolled using this dice.
    • generateRoll

      public abstract Roll generateRoll(int value)
      Generates a roll with value value using this dice. This does not update the state of the dice.
      Parameters:
      value - The value of the dice to be rolled.
      Returns:
      A roll with value value of this dice.
    • roll

      public Roll roll()
      Generates a random roll using this dice.
      Returns:
      A random roll of this dice.
    • roll

      public Roll roll(int value)
      Generates a roll with value value using this dice.
      Parameters:
      value - The value of the dice to be rolled.
      Returns:
      A roll with value value of this dice.