aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-03-16 07:09:02 +0100
committerPacien TRAN-GIRARD2016-03-16 07:09:02 +0100
commit383079bb6082944391f1841fca38edd2e5af54fe (patch)
tree847b86bd5bc8ac85673ee49660bddd85f8b84c72 /src
parent6f3a8a0946946e28213967a98b5f080e3cb2a5e1 (diff)
downloadxblast-383079bb6082944391f1841fca38edd2e5af54fe.tar.gz
Add random bonus generator
Diffstat (limited to 'src')
-rw-r--r--src/ch/epfl/xblast/server/GameState.java26
1 files changed, 26 insertions, 0 deletions
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
@@ -22,6 +22,22 @@ public final class GameState {
22 private static final List<List<PlayerID>> PLAYER_PRIORITY_ORDERS = GameState.buildPlayerPriorityOrderList(); 22 private static final List<List<PlayerID>> PLAYER_PRIORITY_ORDERS = GameState.buildPlayerPriorityOrderList();
23 23
24 /** 24 /**
25 * The list of bonuses to choose randomly from.
26 */
27 private static final Block[] RANDOM_BONUSES = new Block[]{Block.BONUS_BOMB, Block.BONUS_RANGE, Block.FREE};
28
29 /**
30 * The seed used for random value generation.
31 * Constant between executions to make tests reproducible.
32 */
33 private static final int RANDOM_SEED = 2016;
34
35 /**
36 * Pseudo-random source for randomized behaviours.
37 */
38 private static final Random RANDOM_SOURCE = new Random(GameState.RANDOM_SEED);
39
40 /**
25 * Builds and returns the player priority order permutations. 41 * Builds and returns the player priority order permutations.
26 * 42 *
27 * @return the list of player priority orders 43 * @return the list of player priority orders
@@ -31,6 +47,16 @@ public final class GameState {
31 } 47 }
32 48
33 /** 49 /**
50 * Returns a randomly chosen bonus Block with an equal probability distribution.
51 *
52 * @return a random bonus block
53 */
54 private static Block randomBonus() {
55 int randomIndex = RANDOM_SOURCE.nextInt(GameState.RANDOM_BONUSES.length);
56 return GameState.RANDOM_BONUSES[randomIndex];
57 }
58
59 /**
34 * Filters the given list of players and returns the lively ones. 60 * Filters the given list of players and returns the lively ones.
35 * 61 *
36 * @param players a list of players 62 * @param players a list of players