diff options
Diffstat (limited to 'src/ch/epfl/maze/physical')
-rw-r--r-- | src/ch/epfl/maze/physical/World.java | 12 |
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; | |||
7 | import java.util.EnumSet; | 7 | import java.util.EnumSet; |
8 | import java.util.List; | 8 | import java.util.List; |
9 | import java.util.Set; | 9 | import java.util.Set; |
10 | import 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 | /** |