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/Animal.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/ch/epfl/maze/physical/Animal.java') diff --git a/src/ch/epfl/maze/physical/Animal.java b/src/ch/epfl/maze/physical/Animal.java index 34a1136..04c4baf 100644 --- a/src/ch/epfl/maze/physical/Animal.java +++ b/src/ch/epfl/maze/physical/Animal.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; + /** * Animal inside a {@code World} that can move depending on the available * choices it has at its position. @@ -44,7 +48,20 @@ abstract public class Animal { * World.getChoices(Vector2D)}) * @return The next direction of the animal, chosen in {@code choices} */ - abstract public Direction move(Direction[] choices); + abstract public Direction move(Set choices); + + /** + * Retrieves the next direction of the animal, by selecting one choice among + * the ones available from its position. + * + * @param choices The choices left to the animal at its current position (see + * {@link ch.epfl.maze.physical.World#getChoices(Vector2D) + * World.getChoices(Vector2D)}) + * @return The next direction of the animal, chosen in {@code choices} + */ + public final Direction move(Direction[] choices) { + return this.move(EnumSet.copyOf(Arrays.asList(choices))); + } /** * Updates the animal position with a direction. -- cgit v1.2.3