From f312719bf9df140a22406a4e40c5221a86cd8073 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 24 Nov 2015 21:56:22 +0100 Subject: Refactor Daedalus residence --- src/ch/epfl/maze/physical/DaedalusAware.java | 54 ++++++++++++++++++++++ src/ch/epfl/maze/physical/Predator.java | 46 +----------------- src/ch/epfl/maze/physical/Prey.java | 46 +----------------- .../physical/stragegies/picker/BlindPicker.java | 4 +- .../physical/stragegies/picker/ChoicePicker.java | 11 +++-- .../stragegies/reducer/BlindChoiceReducer.java | 4 +- .../physical/stragegies/reducer/CaseReducer.java | 12 ++--- .../physical/stragegies/reducer/ChoiceReducer.java | 8 ++-- 8 files changed, 76 insertions(+), 109 deletions(-) create mode 100644 src/ch/epfl/maze/physical/DaedalusAware.java (limited to 'src/ch') diff --git a/src/ch/epfl/maze/physical/DaedalusAware.java b/src/ch/epfl/maze/physical/DaedalusAware.java new file mode 100644 index 0000000..16f20ee --- /dev/null +++ b/src/ch/epfl/maze/physical/DaedalusAware.java @@ -0,0 +1,54 @@ +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; + +/** + * @author Pacien TRAN-GIRARD + */ +public interface DaedalusAware { + + /** + * 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 hunt or 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} + * @implNote Not abstract for compatibility purpose (in order not to break tests) + */ + default Direction move(Set choices, Daedalus daedalus) { + return null; + } + + /** + * 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 hunt or 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} + * @apiNote Not final for compatibility purpose (in order not to break tests) + * @deprecated Use @code{Direction move(Set choices, Daedalus daedalus)} instead + */ + default Direction move(Direction[] choices, Daedalus daedalus) { + return this.move(EnumSet.copyOf(Arrays.asList(choices)), daedalus); + } + +} diff --git a/src/ch/epfl/maze/physical/Predator.java b/src/ch/epfl/maze/physical/Predator.java index ad5900e..9cc7256 100644 --- a/src/ch/epfl/maze/physical/Predator.java +++ b/src/ch/epfl/maze/physical/Predator.java @@ -1,19 +1,14 @@ 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; - /** * Predator that kills a prey when they meet with each other in the labyrinth. * * @author EPFL * @author Pacien TRAN-GIRARD */ -abstract public class Predator extends ProbabilisticAnimal { +abstract public class Predator extends Animal implements DaedalusAware { /** * Constructs a predator with a specified position. @@ -24,43 +19,4 @@ abstract public class Predator extends ProbabilisticAnimal { super(position); } - /** - * 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 hunt 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} - * @implNote Not abstract for compatibility purpose (in order not to break tests) - */ - public Direction move(Set choices, Daedalus daedalus) { - return null; - } - - /** - * 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 hunt 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} - * @apiNote Not final for compatibility purpose (in order not to break tests) - * @deprecated Use @code{Direction move(Set choices, Daedalus daedalus)} instead - */ - public Direction move(Direction[] choices, Daedalus daedalus) { - return this.move(EnumSet.copyOf(Arrays.asList(choices)), daedalus); - } - } diff --git a/src/ch/epfl/maze/physical/Prey.java b/src/ch/epfl/maze/physical/Prey.java index ff760c5..0ad62ff 100644 --- a/src/ch/epfl/maze/physical/Prey.java +++ b/src/ch/epfl/maze/physical/Prey.java @@ -1,19 +1,14 @@ 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. * * @author EPFL * @author Pacien TRAN-GIRARD */ -abstract public class Prey extends ProbabilisticAnimal { +abstract public class Prey extends Animal implements DaedalusAware { /** * Constructs a prey with a specified position. @@ -24,43 +19,4 @@ abstract public class Prey extends ProbabilisticAnimal { super(position); } - /** - * 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} - * @implNote Not abstract for compatibility purpose (in order not to break tests) - */ - public Direction move(Set choices, Daedalus daedalus) { - return null; - } - - /** - * 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} - * @apiNote Not final for compatibility purpose (in order not to break tests) - * @deprecated Use @code{Direction move(Set choices, Daedalus daedalus)} instead - */ - public Direction move(Direction[] choices, Daedalus daedalus) { - return this.move(EnumSet.copyOf(Arrays.asList(choices)), daedalus); - } - } diff --git a/src/ch/epfl/maze/physical/stragegies/picker/BlindPicker.java b/src/ch/epfl/maze/physical/stragegies/picker/BlindPicker.java index 6dcf229..02cb1ef 100644 --- a/src/ch/epfl/maze/physical/stragegies/picker/BlindPicker.java +++ b/src/ch/epfl/maze/physical/stragegies/picker/BlindPicker.java @@ -1,6 +1,6 @@ package ch.epfl.maze.physical.stragegies.picker; -import ch.epfl.maze.physical.World; +import ch.epfl.maze.physical.Daedalus; import ch.epfl.maze.util.Direction; import java.util.Set; @@ -13,7 +13,7 @@ import java.util.Set; public interface BlindPicker extends ChoicePicker { @Override - default Direction pick(Set choices, World world) { + default Direction pick(Set choices, Daedalus daedalus) { return this.pick(choices); } diff --git a/src/ch/epfl/maze/physical/stragegies/picker/ChoicePicker.java b/src/ch/epfl/maze/physical/stragegies/picker/ChoicePicker.java index 76fe3eb..756c446 100644 --- a/src/ch/epfl/maze/physical/stragegies/picker/ChoicePicker.java +++ b/src/ch/epfl/maze/physical/stragegies/picker/ChoicePicker.java @@ -1,5 +1,6 @@ package ch.epfl.maze.physical.stragegies.picker; +import ch.epfl.maze.physical.Daedalus; import ch.epfl.maze.physical.World; import ch.epfl.maze.util.Direction; import ch.epfl.maze.util.Vector2D; @@ -33,12 +34,12 @@ public interface ChoicePicker { * In this variation, the animal knows the world entirely. It can therefore * use the position of other animals in the daedalus to move 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 world The world in which the animal moves + * @param choices The choices left to the animal at its current position (see + * {@link World#getChoices(Vector2D) + * World.getChoices(Vector2D)}) + * @param daedalus The daedalus in which the animal moves * @return The next direction of the animal, chosen in {@code choices} */ - Direction pick(Set choices, World world); + Direction pick(Set choices, Daedalus daedalus); } diff --git a/src/ch/epfl/maze/physical/stragegies/reducer/BlindChoiceReducer.java b/src/ch/epfl/maze/physical/stragegies/reducer/BlindChoiceReducer.java index 169a8f6..2e8a198 100644 --- a/src/ch/epfl/maze/physical/stragegies/reducer/BlindChoiceReducer.java +++ b/src/ch/epfl/maze/physical/stragegies/reducer/BlindChoiceReducer.java @@ -1,6 +1,6 @@ package ch.epfl.maze.physical.stragegies.reducer; -import ch.epfl.maze.physical.World; +import ch.epfl.maze.physical.Daedalus; import ch.epfl.maze.util.Direction; import java.util.Set; @@ -13,7 +13,7 @@ import java.util.Set; public interface BlindChoiceReducer extends ChoiceReducer { @Override - default Set reduce(Set choices, World world) { + default Set reduce(Set choices, Daedalus daedalus) { return this.reduce(choices); } diff --git a/src/ch/epfl/maze/physical/stragegies/reducer/CaseReducer.java b/src/ch/epfl/maze/physical/stragegies/reducer/CaseReducer.java index 837bd4b..71de287 100644 --- a/src/ch/epfl/maze/physical/stragegies/reducer/CaseReducer.java +++ b/src/ch/epfl/maze/physical/stragegies/reducer/CaseReducer.java @@ -1,6 +1,6 @@ package ch.epfl.maze.physical.stragegies.reducer; -import ch.epfl.maze.physical.World; +import ch.epfl.maze.physical.Daedalus; import ch.epfl.maze.util.Direction; import java.util.Set; @@ -16,17 +16,17 @@ public interface CaseReducer extends ChoiceReducer { /** * Checks if the given choice should be kept or excluded by the filter. * - * @param choice A Direction - * @param world The World + * @param choice A Direction + * @param daedalus The Daedalus * @return T(The filter should keep the given choice) */ - boolean keepChoice(Direction choice, World world); + boolean keepChoice(Direction choice, Daedalus daedalus); @Override - default Set reduce(Set choices, World world) { + default Set reduce(Set choices, Daedalus daedalus) { return choices .stream() - .filter(choice -> this.keepChoice(choice, world)) + .filter(choice -> this.keepChoice(choice, daedalus)) .collect(Collectors.toSet()); } diff --git a/src/ch/epfl/maze/physical/stragegies/reducer/ChoiceReducer.java b/src/ch/epfl/maze/physical/stragegies/reducer/ChoiceReducer.java index 3cb744d..c7e8833 100644 --- a/src/ch/epfl/maze/physical/stragegies/reducer/ChoiceReducer.java +++ b/src/ch/epfl/maze/physical/stragegies/reducer/ChoiceReducer.java @@ -1,8 +1,7 @@ package ch.epfl.maze.physical.stragegies.reducer; -import ch.epfl.maze.physical.World; +import ch.epfl.maze.physical.Daedalus; import ch.epfl.maze.util.Direction; -import ch.epfl.maze.util.Vector2D; import java.util.Set; @@ -26,9 +25,10 @@ public interface ChoiceReducer { * In this variation, the animal knows the world entirely. It can therefore * use the position of other animals in the world to move more effectively. * - * @param choices The choices left to the animal + * @param choices The choices left to the animal + * @param daedalus The daedalus in which the animal moves * @return A subset of possible direction of the animal, chosen in {@code choices} */ - Set reduce(Set choices, World world); + Set reduce(Set choices, Daedalus daedalus); } -- cgit v1.2.3