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 random walk. */ @Override public Direction move(Direction[] choices) { if (choices.length == 0) return Direction.NONE; return choices[randomSource.nextInt(choices.length)]; } }