From e2354d82e09c3bf8ae472d174332670d2d12f9bb Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 24 Nov 2015 14:28:26 +0100 Subject: Use Set instead of array for Direction choices --- src/ch/epfl/maze/physical/Prey.java | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/ch/epfl/maze/physical/Prey.java') diff --git a/src/ch/epfl/maze/physical/Prey.java b/src/ch/epfl/maze/physical/Prey.java index 26fe92b..3654807 100644 --- a/src/ch/epfl/maze/physical/Prey.java +++ b/src/ch/epfl/maze/physical/Prey.java @@ -3,6 +3,10 @@ package ch.epfl.maze.physical; import ch.epfl.maze.util.Direction; import ch.epfl.maze.util.Vector2D; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.Set; + /** * Prey that is killed by a predator when they meet each other in the labyrinth. * @@ -34,6 +38,24 @@ abstract public class Prey extends ProbabilisticAnimal { * @param daedalus The world in which the animal moves * @return The next direction of the animal, chosen in {@code choices} */ - abstract public Direction move(Direction[] choices, Daedalus daedalus); + abstract public Direction move(Set choices, Daedalus daedalus); + + /** + * Retrieves the next direction of the animal, by selecting one choice among + * the ones available from its position. + *

+ * In this variation, the animal knows the world entirely. It can therefore + * use the position of other animals in the daedalus to evade predators more + * effectively. + * + * @param choices The choices left to the animal at its current position (see + * {@link ch.epfl.maze.physical.World#getChoices(Vector2D) + * World.getChoices(Vector2D)}) + * @param daedalus The world in which the animal moves + * @return The next direction of the animal, chosen in {@code choices} + */ + public final Direction move(Direction[] choices, Daedalus daedalus) { + return this.move(EnumSet.copyOf(Arrays.asList(choices)), daedalus); + } } -- cgit v1.2.3