summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/maze/physical')
-rw-r--r--src/ch/epfl/maze/physical/World.java12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/ch/epfl/maze/physical/World.java b/src/ch/epfl/maze/physical/World.java
index 257fa65..9f4f155 100644
--- a/src/ch/epfl/maze/physical/World.java
+++ b/src/ch/epfl/maze/physical/World.java
@@ -7,6 +7,7 @@ import java.util.ArrayList;
7import java.util.EnumSet; 7import java.util.EnumSet;
8import java.util.List; 8import java.util.List;
9import java.util.Set; 9import java.util.Set;
10import java.util.stream.Collectors;
10 11
11/** 12/**
12 * World that is represented by a labyrinth of tiles in which an {@code Animal} 13 * World that is represented by a labyrinth of tiles in which an {@code Animal}
@@ -136,13 +137,12 @@ public abstract class World {
136 * @return A set of all available choices at a position 137 * @return A set of all available choices at a position
137 */ 138 */
138 public final Set<Direction> getChoiceSet(Vector2D position) { 139 public final Set<Direction> getChoiceSet(Vector2D position) {
139 Set<Direction> choices = EnumSet.noneOf(Direction.class); 140 Set<Direction> freeDirections = Direction.MOVING_DIRECTIONS
141 .stream()
142 .filter(dir -> this.isFree(position.addDirectionTo(dir)))
143 .collect(Collectors.toSet());
140 144
141 for (Direction dir : Direction.POSSIBLE_DIRECTIONS) 145 return freeDirections.isEmpty() ? EnumSet.of(Direction.NONE) : freeDirections;
142 if (this.isFree(position.addDirectionTo(dir)))
143 choices.add(dir);
144
145 return choices.isEmpty() ? EnumSet.of(Direction.NONE) : choices;
146 } 146 }
147 147
148 /** 148 /**