aboutsummaryrefslogtreecommitdiff
path: root/src/ch/epfl
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-03-25 16:30:39 +0100
committerPacien TRAN-GIRARD2016-03-25 16:30:39 +0100
commitfa66073ed8bb68b144c3e7397ef95ce0d8442ae8 (patch)
tree60598ddee678d8b99e1ef64e2b56728488cca4f3 /src/ch/epfl
parentc894d8b455f259e341f79de00e20ab3e3170c211 (diff)
downloadxblast-fa66073ed8bb68b144c3e7397ef95ce0d8442ae8.tar.gz
Import given random event generator debugging utility
Diffstat (limited to 'src/ch/epfl')
-rw-r--r--src/ch/epfl/xblast/server/debug/RandomEventGenerator.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/ch/epfl/xblast/server/debug/RandomEventGenerator.java b/src/ch/epfl/xblast/server/debug/RandomEventGenerator.java
new file mode 100644
index 0000000..60a9c62
--- /dev/null
+++ b/src/ch/epfl/xblast/server/debug/RandomEventGenerator.java
@@ -0,0 +1,50 @@
1package ch.epfl.xblast.server.debug;
2
3import ch.epfl.xblast.Direction;
4import ch.epfl.xblast.PlayerID;
5
6import java.util.*;
7
8/**
9 * Random event generator debugging utility.
10 *
11 * @author EPFL
12 */
13public final class RandomEventGenerator {
14
15 private static final List<Optional<Direction>> possibleSpeeds =
16 Arrays.asList(
17 Optional.empty(),
18 Optional.of(Direction.N),
19 Optional.of(Direction.E),
20 Optional.of(Direction.S),
21 Optional.of(Direction.W));
22
23 private final Random rng;
24 private final int speedChangeProb, bombProb;
25
26 public RandomEventGenerator(long seed, int speedChangeProb, int bombProb) {
27 this.rng = new Random(seed);
28 this.speedChangeProb = speedChangeProb;
29 this.bombProb = bombProb;
30 }
31
32 public Map<PlayerID, Optional<Direction>> randomSpeedChangeEvents() {
33 Map<PlayerID, Optional<Direction>> events = new EnumMap<>(PlayerID.class);
34 for (PlayerID pId : PlayerID.values()) {
35 if (rng.nextInt(speedChangeProb) == 0)
36 events.put(pId, possibleSpeeds.get(rng.nextInt(possibleSpeeds.size())));
37 }
38 return Collections.unmodifiableMap(events);
39 }
40
41 public Set<PlayerID> randomBombDropEvents() {
42 Set<PlayerID> events = EnumSet.noneOf(PlayerID.class);
43 for (PlayerID pID : PlayerID.values()) {
44 if (rng.nextInt(bombProb) == 0)
45 events.add(pID);
46 }
47 return Collections.unmodifiableSet(events);
48 }
49
50}