From 9dfd4cbfce88951f196cfbb86154d7d7b2320cf3 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 21 Nov 2015 17:31:08 +0100 Subject: Add ProbabilisticAnimal type and adapt assets retrieval accordingly --- src/ch/epfl/maze/physical/ProbabilisticAnimal.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/ch/epfl/maze/physical/ProbabilisticAnimal.java (limited to 'src/ch/epfl/maze/physical') 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 @@ +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) { + return choices[randomSource.nextInt(choices.length)]; + } + +} -- cgit v1.2.3