summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/World.java
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-11-26 10:00:43 +0100
committerPacien TRAN-GIRARD2015-11-26 10:00:43 +0100
commit1e2eff1e9829f8ffa694f3258433c91c804ab473 (patch)
tree0b0b8b7d7c07cf8ab3b26a1316d54199c18fd5b6 /src/ch/epfl/maze/physical/World.java
parente326c2759d6529048d19c2c913b2b1c264f74485 (diff)
downloadmaze-solver-1e2eff1e9829f8ffa694f3258433c91c804ab473.tar.gz
Improve choice filtering
Diffstat (limited to 'src/ch/epfl/maze/physical/World.java')
-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 /**