summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/stragegies/picker/RandomPicker.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/maze/physical/stragegies/picker/RandomPicker.java')
-rw-r--r--src/ch/epfl/maze/physical/stragegies/picker/RandomPicker.java27
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 @@
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}