Package net.royalur.model.dice
Class Dice
java.lang.Object
net.royalur.model.dice.Dice
- Direct Known Subclasses:
BinaryDice
A generator of dice rolls, that is _not_ necessarily thread-safe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCopies the state ofotherinto this dice.abstract RollgenerateRoll(int value) Generates a roll with valuevalueusing this dice.Gets the type of this dice.getID()Gets the ID of this dice type.abstract intGets the maximum value that could be rolled by this dice.getName()Gets the name of this dice.intCounts the number of rolls with a non-zero probability of being rolled.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.booleanGets whether this dice has an associated dice type.booleanhasState()Returns whether this dice holds any state that affects its dice rolls.voidrecordRoll(int value) Updates the state of this dice after having rolledvalue.roll()Generates a random roll using this dice.roll(int value) Generates a roll with valuevalueusing this dice.abstract intGenerates a random roll using this dice, and returns just the value.
-
Constructor Details
-
Dice
Instantiates this dice with the given ID.
-
-
Method Details
-
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
Gets the type of this dice.- Returns:
- The type of this dice.
-
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, thencopyFrom(Dice)should also be overriden.- Returns:
- Whether this dice holds any state that affects its dice rolls.
-
copyFrom
Copies the state ofotherinto 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, thenhasState()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.
-
getPossibleRollCount
public int getPossibleRollCount()Counts the number of rolls with a non-zero probability of being rolled. -
rollValue
public abstract int rollValue()Generates a random roll using this dice, and returns just the value. If this dice has state, this should callrecordRoll(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 rolledvalue.- Parameters:
value- The value that was rolled using this dice.
-
generateRoll
Generates a roll with valuevalueusing 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
valueof this dice.
-
roll
Generates a random roll using this dice.- Returns:
- A random roll of this dice.
-
roll
Generates a roll with valuevalueusing this dice.- Parameters:
value- The value of the dice to be rolled.- Returns:
- A roll with value
valueof this dice.
-