blob: 6b0c57f4fbb50361c016678826087bd1af7e1952 (
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
28
29
30
31
32
33
34
35
36
37
38
|
package ch.epfl.maze.physical;
import ch.epfl.maze.util.Direction;
import ch.epfl.maze.util.Vector2D;
import java.util.Random;
/**
* A probabilistic animal that use a random component in its decision making process.
*
* @author Pacien TRAN-GIRARD
*/
abstract public class ProbabilisticAnimal extends Animal {
private final Random randomSource;
/**
* Constructs a probabilistic animal with a starting position
*
* @param position Starting position of the probabilistic animal in the labyrinth
*/
public ProbabilisticAnimal(Vector2D position) {
super(position); // no pun intended
this.randomSource = new Random();
}
/**
* Moves according to a <i>random walk</i>.
*/
@Override
public Direction move(Direction[] choices) {
return choices[randomSource.nextInt(choices.length)];
}
}
|