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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Copies the state ofother
into this dice.abstract Roll
generateRoll
(int value) Generates a roll with valuevalue
using this dice.Gets the type of this dice.getID()
Gets the ID of this dice type.abstract int
Gets the maximum value that could be rolled by this dice.getName()
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
hasState()
Returns whether this dice holds any state that affects its dice rolls.void
recordRoll
(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 valuevalue
using this dice.abstract int
Generates 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 ofother
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, 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.
-
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 valuevalue
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
Generates a random roll using this dice.- Returns:
- A random roll of this dice.
-
roll
Generates a roll with valuevalue
using this dice.- Parameters:
value
- The value of the dice to be rolled.- Returns:
- A roll with value
value
of this dice.
-