From 33e497e3083c8446588244c1fa9e69f70af05664 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 24 Nov 2015 15:23:36 +0100 Subject: Refactor Mouse strategy --- .../stragegies/reducer/BackwardReducer.java | 22 ++++++++++++++ .../stragegies/reducer/BlindChoiceReducer.java | 20 +++++++++++++ .../physical/stragegies/reducer/ChoiceReducer.java | 34 ++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/ch/epfl/maze/physical/stragegies/reducer/BackwardReducer.java create mode 100644 src/ch/epfl/maze/physical/stragegies/reducer/BlindChoiceReducer.java create mode 100644 src/ch/epfl/maze/physical/stragegies/reducer/ChoiceReducer.java (limited to 'src/ch/epfl/maze/physical/stragegies/reducer') diff --git a/src/ch/epfl/maze/physical/stragegies/reducer/BackwardReducer.java b/src/ch/epfl/maze/physical/stragegies/reducer/BackwardReducer.java new file mode 100644 index 0000000..4ef2ff8 --- /dev/null +++ b/src/ch/epfl/maze/physical/stragegies/reducer/BackwardReducer.java @@ -0,0 +1,22 @@ +package ch.epfl.maze.physical.stragegies.reducer; + +import ch.epfl.maze.util.Direction; + +import java.util.Set; + +/** + * A filter removing the possibility to go backward. + * + * @author Pacien TRAN-GIRARD + */ +public interface BackwardReducer extends BlindChoiceReducer { + + Direction getDirection(); + + @Override + default Set reduce(Set choices) { + choices.remove(this.getDirection().reverse()); + return choices; + } + +} diff --git a/src/ch/epfl/maze/physical/stragegies/reducer/BlindChoiceReducer.java b/src/ch/epfl/maze/physical/stragegies/reducer/BlindChoiceReducer.java new file mode 100644 index 0000000..169a8f6 --- /dev/null +++ b/src/ch/epfl/maze/physical/stragegies/reducer/BlindChoiceReducer.java @@ -0,0 +1,20 @@ +package ch.epfl.maze.physical.stragegies.reducer; + +import ch.epfl.maze.physical.World; +import ch.epfl.maze.util.Direction; + +import java.util.Set; + +/** + * A decision filter unaware of its distant environment. + * + * @author Pacien TRAN-GIRARD + */ +public interface BlindChoiceReducer extends ChoiceReducer { + + @Override + default Set reduce(Set choices, World world) { + return this.reduce(choices); + } + +} diff --git a/src/ch/epfl/maze/physical/stragegies/reducer/ChoiceReducer.java b/src/ch/epfl/maze/physical/stragegies/reducer/ChoiceReducer.java new file mode 100644 index 0000000..3cb744d --- /dev/null +++ b/src/ch/epfl/maze/physical/stragegies/reducer/ChoiceReducer.java @@ -0,0 +1,34 @@ +package ch.epfl.maze.physical.stragegies.reducer; + +import ch.epfl.maze.physical.World; +import ch.epfl.maze.util.Direction; +import ch.epfl.maze.util.Vector2D; + +import java.util.Set; + +/** + * A choice filter that can exclude choices. + * + * @author Pacien TRAN-GIRARD + */ +public interface ChoiceReducer { + + /** + * Reduces the Direction choices by eliminating the improper ones from the given choices. + * + * @param choices The choices left to the animal + * @return A subset of possible direction of the animal, chosen in {@code choices} + */ + Set reduce(Set choices); + + /** + * Reduces the Direction choices by eliminating the improper ones from the given choices. + * 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 + * @return A subset of possible direction of the animal, chosen in {@code choices} + */ + Set reduce(Set choices, World world); + +} -- cgit v1.2.3