summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-11-22 16:02:57 +0100
committerPacien TRAN-GIRARD2015-11-22 16:02:57 +0100
commit76eba89ebb2da6d19ac37dba5741a717edd8dd8e (patch)
tree201cd475b4e085444c5b13eb593de81f32c95816 /src/ch/epfl/maze/physical
parent751d8761de19ad6e768d5742c6c746b22f514868 (diff)
downloadmaze-solver-76eba89ebb2da6d19ac37dba5741a717edd8dd8e.tar.gz
Generalise and expose choices exclusion methods
Diffstat (limited to 'src/ch/epfl/maze/physical')
-rw-r--r--src/ch/epfl/maze/physical/ProbabilisticAnimal.java21
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;
16abstract public class ProbabilisticAnimal extends Animal { 16abstract 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