summaryrefslogtreecommitdiff
path: root/dice/src/main/java/bjc/dicelang/dicev2/ComputedDie.java
diff options
context:
space:
mode:
Diffstat (limited to 'dice/src/main/java/bjc/dicelang/dicev2/ComputedDie.java')
-rw-r--r--dice/src/main/java/bjc/dicelang/dicev2/ComputedDie.java46
1 files changed, 44 insertions, 2 deletions
diff --git a/dice/src/main/java/bjc/dicelang/dicev2/ComputedDie.java b/dice/src/main/java/bjc/dicelang/dicev2/ComputedDie.java
index 89405fe..4963fcb 100644
--- a/dice/src/main/java/bjc/dicelang/dicev2/ComputedDie.java
+++ b/dice/src/main/java/bjc/dicelang/dicev2/ComputedDie.java
@@ -3,16 +3,41 @@ package bjc.dicelang.dicev2;
import java.util.Random;
import java.util.function.IntSupplier;
+/**
+ * Create a computed die, which gets its values from arbitrary functions.
+ * @author Ben Culkin
+ *
+ */
public class ComputedDie extends Die {
+ /**
+ * The function that provides the number of dice to roll.
+ */
public final IntSupplier numDice;
+ /**
+ * The function that provides the number of sides for the dice.
+ */
public final IntSupplier numSides;
+ /**
+ * Whether or not the number of sides should be rolled once per die.
+ */
public final boolean rerollSides;
+ /**
+ * Create a new computed die.
+ * @param numDice The number of dice to roll.
+ * @param numSides The number of sides on the dice.
+ */
public ComputedDie(IntSupplier numDice, IntSupplier numSides) {
this(numDice, numSides, false);
}
+ /**
+ * Create a new computed die with specified side-roll behavior.
+ * @param numDice The number of dice to roll.
+ * @param numSides The number of sides on the dice.
+ * @param rerollSides Controls whether the number of sides should be rerolled once per die.
+ */
public ComputedDie(IntSupplier numDice, IntSupplier numSides, boolean rerollSides) {
super();
@@ -21,11 +46,24 @@ public class ComputedDie extends Die {
this.rerollSides = rerollSides;
}
-
+
+ /**
+ * Create a new computed die using a specified number of RNGs.
+ * @param rnd The RNG to use.
+ * @param numDice The number of dice to roll.
+ * @param numSides The number of sides on the dice.
+ */
public ComputedDie(Random rnd, IntSupplier numDice, IntSupplier numSides) {
this(rnd, numDice, numSides, false);
}
-
+
+ /**
+ * Create a new computed die using a specified number of RNGs and side-roll behavior.
+ * @param rnd The RNG to use.
+ * @param numDice The number of dice to roll.
+ * @param numSides The number of sides on the dice.
+ * @param rerollSides Controls whether the number of sides should be rerolled once per die.
+ */
public ComputedDie(Random rnd, IntSupplier numDice, IntSupplier numSides, boolean rerollSides) {
super(rnd);
@@ -35,6 +73,7 @@ public class ComputedDie extends Die {
this.rerollSides = rerollSides;
}
+ @Override
public long[] roll() {
int target = numDice.getAsInt();
int sides = numSides.getAsInt();
@@ -50,6 +89,7 @@ public class ComputedDie extends Die {
return res;
}
+ @Override
public long rollSingle() {
return rng.nextInt(numSides.getAsInt());
}
@@ -65,10 +105,12 @@ public class ComputedDie extends Die {
* behavior, otherwise you wouldn't need ComputedDie.
*/
+ @Override
public boolean canOptimize() {
return false;
}
+ @Override
public long optimize() {
throw new UnsupportedOperationException("ComputedDie cannot be optimized");
}