diff options
author | Pacien TRAN-GIRARD | 2015-11-24 14:28:26 +0100 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2015-11-24 14:28:26 +0100 |
commit | e2354d82e09c3bf8ae472d174332670d2d12f9bb (patch) | |
tree | 92528b9231178fd47c6910163360413d4ae77256 /src/ch/epfl/maze/physical/GhostPredator.java | |
parent | 5f9be99e7ebd4a90e666e6efbe9e9d4b3b8008e7 (diff) | |
download | maze-solver-e2354d82e09c3bf8ae472d174332670d2d12f9bb.tar.gz |
Use Set instead of array for Direction choices
Diffstat (limited to 'src/ch/epfl/maze/physical/GhostPredator.java')
-rw-r--r-- | src/ch/epfl/maze/physical/GhostPredator.java | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/ch/epfl/maze/physical/GhostPredator.java b/src/ch/epfl/maze/physical/GhostPredator.java index e4a64b3..c1cfca8 100644 --- a/src/ch/epfl/maze/physical/GhostPredator.java +++ b/src/ch/epfl/maze/physical/GhostPredator.java | |||
@@ -3,8 +3,8 @@ package ch.epfl.maze.physical; | |||
3 | import ch.epfl.maze.util.Direction; | 3 | import ch.epfl.maze.util.Direction; |
4 | import ch.epfl.maze.util.Vector2D; | 4 | import ch.epfl.maze.util.Vector2D; |
5 | 5 | ||
6 | import java.util.ArrayList; | 6 | import java.util.EnumSet; |
7 | import java.util.List; | 7 | import java.util.Set; |
8 | 8 | ||
9 | /** | 9 | /** |
10 | * Predator ghost that have two different modes and a home position in the labyrinth. | 10 | * Predator ghost that have two different modes and a home position in the labyrinth. |
@@ -138,11 +138,11 @@ abstract public class GhostPredator extends Predator { | |||
138 | * Selects the best Direction in the given choices by minimizing the Euclidean distance to the targeted position. | 138 | * Selects the best Direction in the given choices by minimizing the Euclidean distance to the targeted position. |
139 | * | 139 | * |
140 | * @param targetPosition The targeted position | 140 | * @param targetPosition The targeted position |
141 | * @param choices An array of Direction choices | 141 | * @param choices A set of Direction choices |
142 | * @return An array of optimal Direction choices | 142 | * @return A set of optimal Direction choices |
143 | */ | 143 | */ |
144 | private Direction[] selectBestPaths(Vector2D targetPosition, Direction[] choices) { | 144 | private Set<Direction> selectBestPaths(Vector2D targetPosition, Set<Direction> choices) { |
145 | List<Direction> bestPaths = new ArrayList<>(); | 145 | Set<Direction> bestPaths = EnumSet.noneOf(Direction.class); |
146 | double minDist = Double.MAX_VALUE; | 146 | double minDist = Double.MAX_VALUE; |
147 | 147 | ||
148 | for (Direction dir : choices) { | 148 | for (Direction dir : choices) { |
@@ -157,7 +157,7 @@ abstract public class GhostPredator extends Predator { | |||
157 | bestPaths.add(dir); | 157 | bestPaths.add(dir); |
158 | } | 158 | } |
159 | 159 | ||
160 | return bestPaths.toArray(new Direction[bestPaths.size()]); | 160 | return bestPaths; |
161 | } | 161 | } |
162 | 162 | ||
163 | /** | 163 | /** |
@@ -179,11 +179,11 @@ abstract public class GhostPredator extends Predator { | |||
179 | } | 179 | } |
180 | 180 | ||
181 | @Override | 181 | @Override |
182 | public Direction move(Direction[] choices, Daedalus daedalus) { | 182 | public Direction move(Set<Direction> choices, Daedalus daedalus) { |
183 | this.countCycle(); | 183 | this.countCycle(); |
184 | 184 | ||
185 | Direction[] smartChoices = choices.length > 1 ? this.excludeOrigin(choices) : choices; | 185 | Set<Direction> smartChoices = choices.size() > 1 ? this.excludeOrigin(choices) : choices; |
186 | Direction[] bestPaths = this.selectBestPaths(this.getTargetPosition(daedalus), smartChoices); | 186 | Set<Direction> bestPaths = this.selectBestPaths(this.getTargetPosition(daedalus), smartChoices); |
187 | return this.move(bestPaths); | 187 | return this.move(bestPaths); |
188 | } | 188 | } |
189 | 189 | ||