From fa66073ed8bb68b144c3e7397ef95ce0d8442ae8 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Fri, 25 Mar 2016 16:30:39 +0100 Subject: Import given random event generator debugging utility --- .../xblast/server/debug/RandomEventGenerator.java | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/ch/epfl/xblast/server/debug/RandomEventGenerator.java 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 @@ +package ch.epfl.xblast.server.debug; + +import ch.epfl.xblast.Direction; +import ch.epfl.xblast.PlayerID; + +import java.util.*; + +/** + * Random event generator debugging utility. + * + * @author EPFL + */ +public final class RandomEventGenerator { + + private static final List> possibleSpeeds = + Arrays.asList( + Optional.empty(), + Optional.of(Direction.N), + Optional.of(Direction.E), + Optional.of(Direction.S), + Optional.of(Direction.W)); + + private final Random rng; + private final int speedChangeProb, bombProb; + + public RandomEventGenerator(long seed, int speedChangeProb, int bombProb) { + this.rng = new Random(seed); + this.speedChangeProb = speedChangeProb; + this.bombProb = bombProb; + } + + public Map> randomSpeedChangeEvents() { + Map> events = new EnumMap<>(PlayerID.class); + for (PlayerID pId : PlayerID.values()) { + if (rng.nextInt(speedChangeProb) == 0) + events.put(pId, possibleSpeeds.get(rng.nextInt(possibleSpeeds.size()))); + } + return Collections.unmodifiableMap(events); + } + + public Set randomBombDropEvents() { + Set events = EnumSet.noneOf(PlayerID.class); + for (PlayerID pID : PlayerID.values()) { + if (rng.nextInt(bombProb) == 0) + events.add(pID); + } + return Collections.unmodifiableSet(events); + } + +} -- cgit v1.2.3