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/RandomPicker.java | |
parent | 6f2f503bbf75901273376c8c009a6b96886650c8 (diff) | |
download | maze-solver-33e497e3083c8446588244c1fa9e69f70af05664.tar.gz |
Refactor Mouse strategy
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 | } | ||