diff options
Diffstat (limited to 'src/ch/epfl/maze/physical/stragegies/picker/CyclePicker.java')
-rw-r--r-- | src/ch/epfl/maze/physical/stragegies/picker/CyclePicker.java | 41 |
1 files changed, 41 insertions, 0 deletions
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 @@ | |||
1 | package ch.epfl.maze.physical.stragegies.picker; | ||
2 | |||
3 | import ch.epfl.maze.util.Direction; | ||
4 | |||
5 | import java.util.Set; | ||
6 | |||
7 | /** | ||
8 | * A decision maker cycling in each Direction starting from a given one. | ||
9 | * | ||
10 | * @author Pacien TRAN-GIRARD | ||
11 | */ | ||
12 | public interface CyclePicker extends BlindPicker { | ||
13 | |||
14 | /** | ||
15 | * Returns the cycle starting Direction. | ||
16 | * | ||
17 | * @return The starting Direction | ||
18 | */ | ||
19 | Direction getStartingDirection(); | ||
20 | |||
21 | /** | ||
22 | * Returns the Rotation Direction. | ||
23 | * | ||
24 | * @return The Rotation Direction | ||
25 | */ | ||
26 | Direction getRotationDirection(); | ||
27 | |||
28 | @Override | ||
29 | default Direction pick(Set<Direction> choices) { | ||
30 | if (choices.isEmpty()) return FALLBACK_DIRECTION; | ||
31 | if (this.getStartingDirection() == Direction.NONE) return FALLBACK_DIRECTION; | ||
32 | if (this.getRotationDirection() == Direction.NONE) return FALLBACK_DIRECTION; | ||
33 | |||
34 | Direction dir = this.getStartingDirection(); | ||
35 | while (!choices.contains(dir)) | ||
36 | dir = dir.unRelativeDirection(this.getRotationDirection()); | ||
37 | |||
38 | return dir; | ||
39 | } | ||
40 | |||
41 | } | ||