summaryrefslogtreecommitdiff
path: root/dice/src/main/java/bjc/dicelang/dicev2/Die.java
blob: 9fadb2d276a9389403bc2de1a6905670b19babdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package bjc.dicelang.dicev2;

import java.util.Random;

/**
 * An abstract class that represents a single pool of dice.
 * 
 * @author Ben Culkin
 *
 */
public abstract class Die {
	private static final Random BASE = new Random();

	/**
	 * The RNG to use.
	 */
	protected Random rng;

	/**
	 * Create a new basic die.
	 */
	protected Die() {
		rng = BASE;
	}

	/**
	 * Create a new basic die.
	 * 
	 * @param rnd
	 *            The RNG to use.
	 */
	protected Die(Random rnd) {
		rng = rnd;
	}

	/**
	 * Set the RNG this die pool uses.
	 * 
	 * @param rnd
	 *            The RNG used by the die pool.
	 */
	public void setRandom(Random rnd) {
		rng = rnd;
	}

	/**
	 * Roll the entire die pool.
	 * 
	 * @return The results from rolling the dice.
	 */
	public abstract long[] roll();

	/**
	 * Roll a single die in the pool.
	 * 
	 * For pools with multiple die, this may be somewhat arbitrary.
	 * 
	 * @return Result from rolling a single die in the pool.
	 */
	public abstract long rollSingle();

	/**
	 * Can this pool be optimized?
	 * 
	 * @return Is the pool optimizable?
	 */
	public abstract boolean canOptimize();

	/**
	 * Optimize the die pool.
	 * 
	 * Is undefined if called while canOptimize is false.
	 * 
	 * @return The optimized version of the pool.
	 */
	public abstract long optimize();
}