summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/ProbabilisticAnimal.java
blob: f62fea129cc0e2211caf3740f16e026b4d0d4f3e (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
39
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) {
        if (choices.length == 0) return Direction.NONE;
        return choices[randomSource.nextInt(choices.length)];
    }

}