diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ch/epfl/maze/physical/ProbabilisticAnimal.java | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/ch/epfl/maze/physical/ProbabilisticAnimal.java b/src/ch/epfl/maze/physical/ProbabilisticAnimal.java index c4d4f2a..6267500 100644 --- a/src/ch/epfl/maze/physical/ProbabilisticAnimal.java +++ b/src/ch/epfl/maze/physical/ProbabilisticAnimal.java | |||
@@ -16,7 +16,7 @@ import java.util.stream.Collectors; | |||
16 | abstract public class ProbabilisticAnimal extends Animal { | 16 | abstract public class ProbabilisticAnimal extends Animal { |
17 | 17 | ||
18 | private final Random randomSource; | 18 | private final Random randomSource; |
19 | private Direction currentDirection; | 19 | protected Direction currentDirection; |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Constructs a probabilistic animal with a starting position | 22 | * Constructs a probabilistic animal with a starting position |
@@ -30,20 +30,31 @@ abstract public class ProbabilisticAnimal extends Animal { | |||
30 | } | 30 | } |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Excludes the origin direction for choices. | 33 | * Excludes the given direction from possible choices. |
34 | * | 34 | * |
35 | * @param choices An array of choices | 35 | * @param choices An array of choices |
36 | * @param toExclude The Direction to exclude | ||
36 | * @return An array of smart choices | 37 | * @return An array of smart choices |
37 | */ | 38 | */ |
38 | protected Direction[] excludeOrigin(Direction[] choices) { | 39 | protected Direction[] excludeDirection(Direction[] choices, Direction toExclude) { |
39 | return (new ArrayList<>(Arrays.asList(choices))) | 40 | return (new ArrayList<>(Arrays.asList(choices))) |
40 | .stream() | 41 | .stream() |
41 | .filter(dir -> !dir.isOpposite(this.currentDirection)) | 42 | .filter(dir -> dir != toExclude) |
42 | .collect(Collectors.toList()) | 43 | .collect(Collectors.toList()) |
43 | .toArray(new Direction[0]); | 44 | .toArray(new Direction[0]); |
44 | } | 45 | } |
45 | 46 | ||
46 | /** | 47 | /** |
48 | * Excludes the origin direction from possible choices. | ||
49 | * | ||
50 | * @param choices An array of choices | ||
51 | * @return An array of smart choices | ||
52 | */ | ||
53 | protected Direction[] excludeOrigin(Direction[] choices) { | ||
54 | return this.excludeDirection(choices, this.currentDirection.reverse()); | ||
55 | } | ||
56 | |||
57 | /** | ||
47 | * Returns a random Direction from the given choices. | 58 | * Returns a random Direction from the given choices. |
48 | * | 59 | * |
49 | * @param choices An array of Direction | 60 | * @param choices An array of Direction |