From 3f5c3d91a084233cfc77635697b3c537adbced74 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 24 Nov 2015 16:33:34 +0100 Subject: Refactor Monkey A.I. --- .../physical/stragegies/picker/CyclePicker.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/ch/epfl/maze/physical/stragegies/picker/CyclePicker.java (limited to 'src/ch/epfl/maze/physical/stragegies/picker/CyclePicker.java') diff --git a/src/ch/epfl/maze/physical/stragegies/picker/CyclePicker.java b/src/ch/epfl/maze/physical/stragegies/picker/CyclePicker.java new file mode 100644 index 0000000..e1a969f --- /dev/null +++ b/src/ch/epfl/maze/physical/stragegies/picker/CyclePicker.java @@ -0,0 +1,41 @@ +package ch.epfl.maze.physical.stragegies.picker; + +import ch.epfl.maze.util.Direction; + +import java.util.Set; + +/** + * A decision maker cycling in each Direction starting from a given one. + * + * @author Pacien TRAN-GIRARD + */ +public interface CyclePicker extends BlindPicker { + + /** + * Returns the cycle starting Direction. + * + * @return The starting Direction + */ + Direction getStartingDirection(); + + /** + * Returns the Rotation Direction. + * + * @return The Rotation Direction + */ + Direction getRotationDirection(); + + @Override + default Direction pick(Set choices) { + if (choices.isEmpty()) return FALLBACK_DIRECTION; + if (this.getStartingDirection() == Direction.NONE) return FALLBACK_DIRECTION; + if (this.getRotationDirection() == Direction.NONE) return FALLBACK_DIRECTION; + + Direction dir = this.getStartingDirection(); + while (!choices.contains(dir)) + dir = dir.unRelativeDirection(this.getRotationDirection()); + + return dir; + } + +} -- cgit v1.2.3