aboutsummaryrefslogtreecommitdiff
path: root/src/ch
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch')
-rw-r--r--src/ch/epfl/xblast/server/GameState.java30
1 files changed, 3 insertions, 27 deletions
diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java
index 2fbea45..364a564 100644
--- a/src/ch/epfl/xblast/server/GameState.java
+++ b/src/ch/epfl/xblast/server/GameState.java
@@ -203,7 +203,7 @@ public final class GameState {
203 Direction requestedDirection) { 203 Direction requestedDirection) {
204 204
205 // 1. Compute the new path to follow 205 // 1. Compute the new path to follow
206 Sq<Player.DirectedPosition> updatedPath = GameState.nextPath(player0, requestedDirection); 206 Sq<Player.DirectedPosition> updatedPath = GameState.nextPath(player0.directedPositions(), requestedDirection);
207 207
208 // 2. Follow the path if the Player can (moving life state and no collision) 208 // 2. Follow the path if the Player can (moving life state and no collision)
209 Sq<Player.DirectedPosition> directedPos1 = GameState.moveAhead(player0, updatedPath, board1, bombedCells1); 209 Sq<Player.DirectedPosition> directedPos1 = GameState.moveAhead(player0, updatedPath, board1, bombedCells1);
@@ -222,38 +222,14 @@ public final class GameState {
222 } 222 }
223 223
224 /** 224 /**
225 * Returns the next Direction of the Player according to the constraints.
226 *
227 * @param p0 the Player
228 * @param requestedDir the requested new Direction
229 * @return the next Direction
230 */
231 private static Direction nextDirection(Player p0, Direction requestedDir) {
232 return !Objects.isNull(requestedDir) ? requestedDir : p0.direction();
233 }
234
235 /**
236 * Generates the new Sequence of DirectedPositions.
237 *
238 * @param p0 the Player
239 * @param requestedDir the new requested Direction
240 * @return the next path
241 */
242 private static Sq<Player.DirectedPosition> nextPath(Player p0, Direction requestedDir) {
243 return GameState.newPath(
244 p0.directedPositions(),
245 GameState.nextDirection(p0, requestedDir));
246 }
247
248 /**
249 * Computes the new path to follow according to the Player's wishes and the Board constraints. 225 * Computes the new path to follow according to the Player's wishes and the Board constraints.
250 * 226 *
251 * @param p0 the current path 227 * @param p0 the current path
252 * @param newDir the new requested Direction 228 * @param newDir the new requested Direction
253 * @return the new path 229 * @return the new path
254 */ 230 */
255 private static Sq<Player.DirectedPosition> newPath(Sq<Player.DirectedPosition> p0, Direction newDir) { 231 private static Sq<Player.DirectedPosition> nextPath(Sq<Player.DirectedPosition> p0, Direction newDir) {
256 if (newDir == p0.head().direction()) 232 if (Objects.isNull(newDir))
257 return p0; 233 return p0;
258 234
259 if (p0.head().direction().isPerpendicularTo(newDir)) 235 if (p0.head().direction().isPerpendicularTo(newDir))