blob: c0131f1b62789ed25a83a396172709f967d13261 (
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
|
package bjc.dicelang.dicev2;
import java.util.function.LongUnaryOperator;
/**
* Die pool which executes a mapping on the result.
*
* @author Ben Culkin
*
*/
public class MapDieMod extends Die {
/**
* The die pool.
*/
public final Die die;
/**
* The operator on the result.
*/
public final LongUnaryOperator map;
/**
* Create a new mapping die pool.
*
* @param map The operation to do on the result.
* @param die The die pool.
*/
public MapDieMod(LongUnaryOperator map, Die die) {
super();
this.die = die;
this.map = map;
}
@Override
public long[] roll() {
long[] res = die.roll();
for(int i = 0; i < res.length; i++) {
res[i] = map.applyAsLong(res[i]);
}
return res;
}
@Override
public long rollSingle() {
return map.applyAsLong(die.rollSingle());
}
/* :UnoptimizableDice */
@Override
public boolean canOptimize() {
return false;
}
@Override
public long optimize() {
throw new UnsupportedOperationException("Mapped dice can't be optimized");
}
}
|