diff options
author | Pacien TRAN-GIRARD | 2015-11-24 15:23:36 +0100 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2015-11-24 15:37:19 +0100 |
commit | 33e497e3083c8446588244c1fa9e69f70af05664 (patch) | |
tree | 3ef665e3c9478f196bb6d61dd15a71c0a9919216 /src/ch/epfl/maze/physical/stragegies/picker | |
parent | 6f2f503bbf75901273376c8c009a6b96886650c8 (diff) | |
download | maze-solver-33e497e3083c8446588244c1fa9e69f70af05664.tar.gz |
Refactor Mouse strategy
Diffstat (limited to 'src/ch/epfl/maze/physical/stragegies/picker')
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 @@ | |||
1 | package ch.epfl.maze.physical.stragegies.picker; | ||
2 | |||
3 | import ch.epfl.maze.physical.World; | ||
4 | import ch.epfl.maze.util.Direction; | ||
5 | |||
6 | import java.util.Set; | ||
7 | |||
8 | /** | ||
9 | * A decision maker unaware of its distant environment. | ||
10 | * | ||
11 | * @author Pacien TRAN-GIRARD | ||
12 | */ | ||
13 | public 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 @@ | |||
1 | package ch.epfl.maze.physical.stragegies.picker; | ||
2 | |||
3 | import ch.epfl.maze.physical.World; | ||
4 | import ch.epfl.maze.util.Direction; | ||
5 | import ch.epfl.maze.util.Vector2D; | ||
6 | |||
7 | import java.util.Set; | ||
8 | |||
9 | /** | ||
10 | * A decision maker that can pick a Direction given multiple choices. | ||
11 | * | ||
12 | * @author Pacien TRAN-GIRARD | ||
13 | */ | ||
14 | public 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 @@ | |||
1 | package ch.epfl.maze.physical.stragegies.picker; | ||
2 | |||
3 | import ch.epfl.maze.util.Direction; | ||
4 | |||
5 | import java.util.ArrayList; | ||
6 | import java.util.List; | ||
7 | import java.util.Random; | ||
8 | import java.util.Set; | ||
9 | |||
10 | /** | ||
11 | * A probabilistic decision maker. | ||
12 | * | ||
13 | * @author Pacien TRAN-GIRARD | ||
14 | */ | ||
15 | public 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 | } | ||