diff options
Diffstat (limited to 'src/ch/epfl/maze/physical/stragegies/picker/RandomPicker.java')
-rw-r--r-- | src/ch/epfl/maze/physical/stragegies/picker/RandomPicker.java | 27 |
1 files changed, 27 insertions, 0 deletions
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 | } | ||