From 383079bb6082944391f1841fca38edd2e5af54fe Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Wed, 16 Mar 2016 07:09:02 +0100 Subject: Add random bonus generator --- src/ch/epfl/xblast/server/GameState.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/ch/epfl') diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java index 0512510..5386311 100644 --- a/src/ch/epfl/xblast/server/GameState.java +++ b/src/ch/epfl/xblast/server/GameState.java @@ -21,6 +21,22 @@ public final class GameState { */ private static final List> PLAYER_PRIORITY_ORDERS = GameState.buildPlayerPriorityOrderList(); + /** + * The list of bonuses to choose randomly from. + */ + private static final Block[] RANDOM_BONUSES = new Block[]{Block.BONUS_BOMB, Block.BONUS_RANGE, Block.FREE}; + + /** + * The seed used for random value generation. + * Constant between executions to make tests reproducible. + */ + private static final int RANDOM_SEED = 2016; + + /** + * Pseudo-random source for randomized behaviours. + */ + private static final Random RANDOM_SOURCE = new Random(GameState.RANDOM_SEED); + /** * Builds and returns the player priority order permutations. * @@ -30,6 +46,16 @@ public final class GameState { return Lists.permutations(Arrays.asList(PlayerID.values())); } + /** + * Returns a randomly chosen bonus Block with an equal probability distribution. + * + * @return a random bonus block + */ + private static Block randomBonus() { + int randomIndex = RANDOM_SOURCE.nextInt(GameState.RANDOM_BONUSES.length); + return GameState.RANDOM_BONUSES[randomIndex]; + } + /** * Filters the given list of players and returns the lively ones. * -- cgit v1.2.3