diff options
Diffstat (limited to 'src/ch/epfl/maze/physical/ProbabilisticAnimal.java')
-rw-r--r-- | src/ch/epfl/maze/physical/ProbabilisticAnimal.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/ch/epfl/maze/physical/ProbabilisticAnimal.java b/src/ch/epfl/maze/physical/ProbabilisticAnimal.java new file mode 100644 index 0000000..6b0c57f --- /dev/null +++ b/src/ch/epfl/maze/physical/ProbabilisticAnimal.java | |||
@@ -0,0 +1,38 @@ | |||
1 | package ch.epfl.maze.physical; | ||
2 | |||
3 | import ch.epfl.maze.util.Direction; | ||
4 | import ch.epfl.maze.util.Vector2D; | ||
5 | |||
6 | import java.util.Random; | ||
7 | |||
8 | /** | ||
9 | * A probabilistic animal that use a random component in its decision making process. | ||
10 | * | ||
11 | * @author Pacien TRAN-GIRARD | ||
12 | */ | ||
13 | |||
14 | abstract public class ProbabilisticAnimal extends Animal { | ||
15 | |||
16 | private final Random randomSource; | ||
17 | |||
18 | /** | ||
19 | * Constructs a probabilistic animal with a starting position | ||
20 | * | ||
21 | * @param position Starting position of the probabilistic animal in the labyrinth | ||
22 | */ | ||
23 | |||
24 | public ProbabilisticAnimal(Vector2D position) { | ||
25 | super(position); // no pun intended | ||
26 | this.randomSource = new Random(); | ||
27 | } | ||
28 | |||
29 | /** | ||
30 | * Moves according to a <i>random walk</i>. | ||
31 | */ | ||
32 | |||
33 | @Override | ||
34 | public Direction move(Direction[] choices) { | ||
35 | return choices[randomSource.nextInt(choices.length)]; | ||
36 | } | ||
37 | |||
38 | } | ||