From 5a45593914a7f96f5d6dfe8526caa5dcc34ac16a Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 24 Nov 2015 18:36:44 +0100 Subject: Add World-aware case reducer --- .../physical/stragegies/reducer/CaseReducer.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/ch/epfl/maze/physical/stragegies/reducer/CaseReducer.java diff --git a/src/ch/epfl/maze/physical/stragegies/reducer/CaseReducer.java b/src/ch/epfl/maze/physical/stragegies/reducer/CaseReducer.java new file mode 100644 index 0000000..837bd4b --- /dev/null +++ b/src/ch/epfl/maze/physical/stragegies/reducer/CaseReducer.java @@ -0,0 +1,33 @@ +package ch.epfl.maze.physical.stragegies.reducer; + +import ch.epfl.maze.physical.World; +import ch.epfl.maze.util.Direction; + +import java.util.Set; +import java.util.stream.Collectors; + +/** + * A filter reducer filtering possibilities case by case. + * + * @author Pacien TRAN-GIRARD + */ +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 + * @return T(The filter should keep the given choice) + */ + boolean keepChoice(Direction choice, World world); + + @Override + default Set reduce(Set choices, World world) { + return choices + .stream() + .filter(choice -> this.keepChoice(choice, world)) + .collect(Collectors.toSet()); + } + +} -- cgit v1.2.3