blob: 427c0eb3c137edee67d4accec0f8855df53592ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package ch.epfl.maze.physical.stragegies.picker;
import ch.epfl.maze.util.Direction;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Set;
/**
* A probabilistic decision maker.
*
* @author Pacien TRAN-GIRARD
*/
public interface RandomPicker extends BlindPicker {
Random RANDOM_SOURCE = new Random();
@Override
default Direction pick(Set<Direction> choices) {
if (choices.isEmpty()) return FALLBACK_DIRECTION;
List<Direction> choiceList = new ArrayList<>(choices);
return choiceList.get(RANDOM_SOURCE.nextInt(choices.size()));
}
}
|