summaryrefslogtreecommitdiff
path: root/src/ch
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch')
-rw-r--r--src/ch/epfl/maze/physical/ProbabilisticAnimal.java16
-rw-r--r--src/ch/epfl/maze/physical/zoo/Panda.java2
2 files changed, 13 insertions, 5 deletions
diff --git a/src/ch/epfl/maze/physical/ProbabilisticAnimal.java b/src/ch/epfl/maze/physical/ProbabilisticAnimal.java
index 45c2175..ed26d23 100644
--- a/src/ch/epfl/maze/physical/ProbabilisticAnimal.java
+++ b/src/ch/epfl/maze/physical/ProbabilisticAnimal.java
@@ -15,8 +15,9 @@ import java.util.stream.Collectors;
15 */ 15 */
16abstract public class ProbabilisticAnimal extends Animal { 16abstract public class ProbabilisticAnimal extends Animal {
17 17
18 private final Random randomSource; 18 public static final Random RANDOM_SOURCE = new Random();
19 protected Direction currentDirection; 19
20 private Direction currentDirection;
20 21
21 /** 22 /**
22 * Constructs a probabilistic animal with a starting position 23 * Constructs a probabilistic animal with a starting position
@@ -25,10 +26,17 @@ abstract public class ProbabilisticAnimal extends Animal {
25 */ 26 */
26 public ProbabilisticAnimal(Vector2D position) { 27 public ProbabilisticAnimal(Vector2D position) {
27 super(position); // no pun intended 28 super(position); // no pun intended
28 this.randomSource = new Random();
29 this.currentDirection = Direction.NONE; 29 this.currentDirection = Direction.NONE;
30 } 30 }
31 31
32 protected Direction getCurrentDirection() {
33 return this.currentDirection;
34 }
35
36 protected void setCurrentDirection(Direction direction) {
37 this.currentDirection = direction;
38 }
39
32 /** 40 /**
33 * Excludes the given direction from possible choices. 41 * Excludes the given direction from possible choices.
34 * 42 *
@@ -61,7 +69,7 @@ abstract public class ProbabilisticAnimal extends Animal {
61 * @return A random Direction taken from the given choices 69 * @return A random Direction taken from the given choices
62 */ 70 */
63 protected Direction getRandomDirection(Direction[] choices) { 71 protected Direction getRandomDirection(Direction[] choices) {
64 return choices[randomSource.nextInt(choices.length)]; 72 return choices[RANDOM_SOURCE.nextInt(choices.length)];
65 } 73 }
66 74
67 /** 75 /**
diff --git a/src/ch/epfl/maze/physical/zoo/Panda.java b/src/ch/epfl/maze/physical/zoo/Panda.java
index fecec84..dc1198e 100644
--- a/src/ch/epfl/maze/physical/zoo/Panda.java
+++ b/src/ch/epfl/maze/physical/zoo/Panda.java
@@ -87,7 +87,7 @@ public class Panda extends ProbabilisticAnimal {
87 private Direction[] selectBestDirections(Direction[] choices) { 87 private Direction[] selectBestDirections(Direction[] choices) {
88 // special case 88 // special case
89 if (this.isIntersection(choices) && this.allChoicesLeadingTo(choices, Trail.Marking.AVOID_MARKING)) 89 if (this.isIntersection(choices) && this.allChoicesLeadingTo(choices, Trail.Marking.AVOID_MARKING))
90 return new Direction[]{this.currentDirection.reverse()}; 90 return new Direction[]{this.getCurrentDirection().reverse()};
91 91
92 // general case 92 // general case
93 for (Trail.Marking mark : Trail.Marking.ALL) { 93 for (Trail.Marking mark : Trail.Marking.ALL) {