aboutsummaryrefslogtreecommitdiff
path: root/src/ch
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-03-15 20:36:43 +0100
committerPacien TRAN-GIRARD2016-03-15 20:36:43 +0100
commit47de23b97f65b9c97e7bce4bb2f4a496e5190bea (patch)
tree6fee2b9d7fc12086dc35d680bec785eb89ae9351 /src/ch
parent3c47558d60a05f3f46674da610a7a550a559b4be (diff)
downloadxblast-47de23b97f65b9c97e7bce4bb2f4a496e5190bea.tar.gz
Make filters and mappers static for easier future state computation
Diffstat (limited to 'src/ch')
-rw-r--r--src/ch/epfl/xblast/server/GameState.java51
1 files changed, 39 insertions, 12 deletions
diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java
index cbe29b5..d750732 100644
--- a/src/ch/epfl/xblast/server/GameState.java
+++ b/src/ch/epfl/xblast/server/GameState.java
@@ -27,7 +27,42 @@ public final class GameState {
27 private final List<Sq<Cell>> blasts; 27 private final List<Sq<Cell>> blasts;
28 28
29 /** 29 /**
30 * Compute the next state of a blast. 30 * Filters the given list of players and returns the lively ones.
31 *
32 * @param players a list of players
33 * @return the list of alive players
34 */
35 private static List<Player> alivePlayers(List<Player> players) {
36 return players.stream()
37 .filter(Player::isAlive)
38 .collect(Collectors.toList());
39 }
40
41 /**
42 * Maps the given bombs to their position.
43 *
44 * @param bombs a list of bombs
45 * @return a map of positions and their bombs
46 */
47 private static Map<Cell, Bomb> bombedCells(List<Bomb> bombs) {
48 return bombs.stream()
49 .collect(Collectors.toMap(Bomb::position, Function.identity()));
50 }
51
52 /**
53 * Returns a set of cells that contains at least one blast in the given blasts sequences.
54 *
55 * @param blasts the list of blast sequences
56 * @return the set of blasted cells
57 */
58 private static Set<Cell> blastedCells(List<Sq<Cell>> blasts) {
59 return blasts.stream()
60 .map(Sq::head)
61 .collect(Collectors.toSet());
62 }
63
64 /**
65 * Computes the next state of a blast.
31 * 66 *
32 * @param blasts0 existing particles 67 * @param blasts0 existing particles
33 * @param board0 the game's board 68 * @param board0 the game's board
@@ -194,10 +229,7 @@ public final class GameState {
194 * @return a list of the alive players 229 * @return a list of the alive players
195 */ 230 */
196 public List<Player> alivePlayers() { 231 public List<Player> alivePlayers() {
197 return this.players 232 return GameState.alivePlayers(this.players);
198 .stream()
199 .filter(Player::isAlive)
200 .collect(Collectors.toList());
201 } 233 }
202 234
203 /** 235 /**
@@ -206,9 +238,7 @@ public final class GameState {
206 * @return the map of bombs 238 * @return the map of bombs
207 */ 239 */
208 public Map<Cell, Bomb> bombedCells() { 240 public Map<Cell, Bomb> bombedCells() {
209 return this.bombs 241 return GameState.bombedCells(this.bombs);
210 .stream()
211 .collect(Collectors.toMap(Bomb::position, Function.identity()));
212 } 242 }
213 243
214 /** 244 /**
@@ -217,10 +247,7 @@ public final class GameState {
217 * @return the set of blasted cells 247 * @return the set of blasted cells
218 */ 248 */
219 public Set<Cell> blastedCells() { 249 public Set<Cell> blastedCells() {
220 return this.blasts 250 return GameState.blastedCells(this.blasts);
221 .stream()
222 .map(Sq::head)
223 .collect(Collectors.toSet());
224 } 251 }
225 252
226 /** 253 /**