blob: 9fababa499c964a5a655daa33d3c21f01460ce41 (
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
|
package bjc.dicelang.dicev2;
import java.util.Random;
/**
* Create a set of Fudge dice.
*
* Fudge dice are dice which can roll -1, 0 or 1.
*
* @author Ben Culkin
*
*/
public class FudgeDie extends Die {
/**
* The number of dice to roll.
*/
public final int numDice;
/**
* Create a new pool for fudge dice.
*
* @param numDice The number of dice in the pool.
*/
public FudgeDie(int numDice) {
super();
this.numDice = numDice;
}
/**
* Create a new pool for fudge dice.
*
* @param rnd The random number generator to use.
* @param numDice The number of dice in the pool.
*/
public FudgeDie(Random rnd, int numDice) {
super(rnd);
this.numDice = numDice;
}
@Override
public long[] roll() {
long[] res = new long[numDice];
for(int i = 0; i < numDice; i++) {
res[i] = rollSingle();
}
return res;
}
@Override
public long rollSingle() {
/* Return an int in the range [-1, 1] */
return rng.nextInt(3) - 1;
}
@Override
public boolean canOptimize() {
return numDice == 0;
}
@Override
public long optimize() {
return 0;
}
}
|