summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/stragegies/picker
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/maze/physical/stragegies/picker')
-rw-r--r--src/ch/epfl/maze/physical/stragegies/picker/BlindPicker.java20
-rw-r--r--src/ch/epfl/maze/physical/stragegies/picker/ChoicePicker.java44
-rw-r--r--src/ch/epfl/maze/physical/stragegies/picker/RandomPicker.java27
3 files changed, 91 insertions, 0 deletions
diff --git a/src/ch/epfl/maze/physical/stragegies/picker/BlindPicker.java b/src/ch/epfl/maze/physical/stragegies/picker/BlindPicker.java
new file mode 100644
index 0000000..6dcf229
--- /dev/null
+++ b/src/ch/epfl/maze/physical/stragegies/picker/BlindPicker.java
@@ -0,0 +1,20 @@
1package ch.epfl.maze.physical.stragegies.picker;
2
3import ch.epfl.maze.physical.World;
4import ch.epfl.maze.util.Direction;
5
6import java.util.Set;
7
8/**
9 * A decision maker unaware of its distant environment.
10 *
11 * @author Pacien TRAN-GIRARD
12 */
13public interface BlindPicker extends ChoicePicker {
14
15 @Override
16 default Direction pick(Set<Direction> choices, World world) {
17 return this.pick(choices);
18 }
19
20}
diff --git a/src/ch/epfl/maze/physical/stragegies/picker/ChoicePicker.java b/src/ch/epfl/maze/physical/stragegies/picker/ChoicePicker.java
new file mode 100644
index 0000000..76fe3eb
--- /dev/null
+++ b/src/ch/epfl/maze/physical/stragegies/picker/ChoicePicker.java
@@ -0,0 +1,44 @@
1package ch.epfl.maze.physical.stragegies.picker;
2
3import ch.epfl.maze.physical.World;
4import ch.epfl.maze.util.Direction;
5import ch.epfl.maze.util.Vector2D;
6
7import java.util.Set;
8
9/**
10 * A decision maker that can pick a Direction given multiple choices.
11 *
12 * @author Pacien TRAN-GIRARD
13 */
14public interface ChoicePicker {
15
16 Direction FALLBACK_DIRECTION = Direction.NONE;
17
18 /**
19 * Retrieves the next direction of the animal, by selecting one choice among
20 * the ones available from its position.
21 *
22 * @param choices The choices left to the animal at its current position (see
23 * {@link ch.epfl.maze.physical.World#getChoices(Vector2D)
24 * World.getChoices(Vector2D)})
25 * @return The next direction of the animal, chosen in {@code choices}
26 */
27 Direction pick(Set<Direction> choices);
28
29 /**
30 * Retrieves the next direction of the animal, by selecting one choice among
31 * the ones available from its position.
32 * <p>
33 * In this variation, the animal knows the world entirely. It can therefore
34 * use the position of other animals in the daedalus to move more effectively.
35 *
36 * @param choices The choices left to the animal at its current position (see
37 * {@link ch.epfl.maze.physical.World#getChoices(Vector2D)
38 * World.getChoices(Vector2D)})
39 * @param world The world in which the animal moves
40 * @return The next direction of the animal, chosen in {@code choices}
41 */
42 Direction pick(Set<Direction> choices, World world);
43
44}
diff --git a/src/ch/epfl/maze/physical/stragegies/picker/RandomPicker.java b/src/ch/epfl/maze/physical/stragegies/picker/RandomPicker.java
new file mode 100644
index 0000000..427c0eb
--- /dev/null
+++ b/src/ch/epfl/maze/physical/stragegies/picker/RandomPicker.java
@@ -0,0 +1,27 @@
1package ch.epfl.maze.physical.stragegies.picker;
2
3import ch.epfl.maze.util.Direction;
4
5import java.util.ArrayList;
6import java.util.List;
7import java.util.Random;
8import java.util.Set;
9
10/**
11 * A probabilistic decision maker.
12 *
13 * @author Pacien TRAN-GIRARD
14 */
15public interface RandomPicker extends BlindPicker {
16
17 Random RANDOM_SOURCE = new Random();
18
19 @Override
20 default Direction pick(Set<Direction> choices) {
21 if (choices.isEmpty()) return FALLBACK_DIRECTION;
22
23 List<Direction> choiceList = new ArrayList<>(choices);
24 return choiceList.get(RANDOM_SOURCE.nextInt(choices.size()));
25 }
26
27}