diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-11-21 23:11:43 -0500 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-11-21 23:11:43 -0500 |
| commit | eda9a86d8d48758e9982cfffd470c3b38a0a4b0b (patch) | |
| tree | fbe073650de751486725844ed41dfe70986a914d /dice/src/main/java/bjc/dicelang/neodice/Die.java | |
| parent | b5c2fb1ed923d43412694729b4445a66fa9f47fc (diff) | |
Make dice generic
Convert dice from dealing exclusively with ints, to deal with objects of
arbitrary types
Diffstat (limited to 'dice/src/main/java/bjc/dicelang/neodice/Die.java')
| -rw-r--r-- | dice/src/main/java/bjc/dicelang/neodice/Die.java | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/dice/src/main/java/bjc/dicelang/neodice/Die.java b/dice/src/main/java/bjc/dicelang/neodice/Die.java deleted file mode 100644 index 9bcbb0f..0000000 --- a/dice/src/main/java/bjc/dicelang/neodice/Die.java +++ /dev/null @@ -1,82 +0,0 @@ -package bjc.dicelang.neodice; - -import java.util.*; -import java.util.function.*; -import java.util.stream.*; - -import bjc.dicelang.neodice.die.*; -import bjc.dicelang.neodice.diepool.*; - -/** - * Represents a single polyhedral die. - * @author Ben Culkin - * - */ -@FunctionalInterface -public interface Die { - /** - * Rolls this die. - * - * @param rng The source for random numbers - * - * @return The result of rolling the die. - */ - public int roll(Random rng); - - /** - * Returns a die pool which rolls this die the specified number of times. - * - * @param numTimes The number of times to roll this die. - * - * @return A die pool that rolls this die the specified number of times. - */ - default DiePool times(int numTimes) { - return new TimesDiePool(this, numTimes); - }; - - /** - * Returns a die which will reroll this die as long as the provided condition is true. - * - * @param condition The condition to reroll the die on. - * - * @return A die that rerolls when the given condition is met. - */ - default Die reroll(IntPredicate condition) { - return new RerollDie(this, condition, (lst) -> lst.get(lst.size())); - } - - /** - * Returns a die which will reroll this die up to a specified number of times, - * as long as the provided condition is true. - * - * @param condition The condition to reroll the die on. - * @param limit The maximum number of times to reroll the die. - * - * @return A die that rerolls when the given condition is met. - */ - default Die reroll(IntPredicate condition, int limit) { - return new RerollDie(this, condition, (lst) -> lst.get(lst.size()), limit); - } - - /** - * Create an iterator which gives rolls of this dice. - * - * @param rng The source for random numbers. - * - * @return An iterator which gives rolls of this dice. - */ - default Iterator<Integer> iterator(Random rng) { - return IntStream.generate(() -> this.roll(rng)).iterator(); - } - - /** - * Create a simple polyhedral die with a fixed number of sides. - * - * @param sides The number of sides for the die. - * - * @return A die which returns a result from 1 to sides. - */ - static Die polyhedral(int sides) { - return new PolyhedralDie(sides); - } -}
\ No newline at end of file |
