summaryrefslogtreecommitdiff
path: root/src/ch
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-11-25 16:58:21 +0100
committerPacien TRAN-GIRARD2015-11-25 16:58:21 +0100
commitc7bff348ec66e535a7146cf48907f4c8d785d623 (patch)
tree067dfd1c8e3c5a89acd842286750ab8a7400c324 /src/ch
parentc5e5646b7785e1b5d1c46efd5e93a6f95d5bad9f (diff)
downloadmaze-solver-c7bff348ec66e535a7146cf48907f4c8d785d623.tar.gz
Remove unused class
Diffstat (limited to 'src/ch')
-rw-r--r--src/ch/epfl/maze/physical/ProbabilisticAnimal.java77
1 files changed, 0 insertions, 77 deletions
diff --git a/src/ch/epfl/maze/physical/ProbabilisticAnimal.java b/src/ch/epfl/maze/physical/ProbabilisticAnimal.java
deleted file mode 100644
index e461e8c..0000000
--- a/src/ch/epfl/maze/physical/ProbabilisticAnimal.java
+++ /dev/null
@@ -1,77 +0,0 @@
1package ch.epfl.maze.physical;
2
3import ch.epfl.maze.util.Direction;
4import ch.epfl.maze.util.Vector2D;
5
6import java.util.ArrayList;
7import java.util.List;
8import java.util.Random;
9import java.util.Set;
10import java.util.stream.Collectors;
11
12/**
13 * A probabilistic animal that uses a random component in its decision making process.
14 *
15 * @author Pacien TRAN-GIRARD
16 */
17abstract public class ProbabilisticAnimal extends Animal {
18
19 public static final Random RANDOM_SOURCE = new Random();
20
21 /**
22 * Constructs a probabilistic animal with a starting position
23 *
24 * @param position Starting position of the probabilistic animal in the labyrinth
25 */
26 public ProbabilisticAnimal(Vector2D position) {
27 super(position); // no pun intended
28 }
29
30 /**
31 * Excludes the given direction from possible choices.
32 *
33 * @param choices A set of choices
34 * @param toExclude The Direction to exclude
35 * @return A set of smart choices
36 */
37 protected Set<Direction> excludeDirection(Set<Direction> choices, Direction toExclude) {
38 return choices
39 .stream()
40 .filter(dir -> dir != toExclude)
41 .collect(Collectors.toSet());
42 }
43
44 /**
45 * Excludes the origin direction from possible choices.
46 *
47 * @param choices A set of choices
48 * @return A set of smart choices
49 */
50 protected Set<Direction> excludeOrigin(Set<Direction> choices) {
51 return this.excludeDirection(choices, this.getDirection().reverse());
52 }
53
54 /**
55 * Returns a random Direction from the given choices.
56 *
57 * @param choices A set of Direction
58 * @return A random Direction taken from the given choices
59 */
60 protected Direction getRandomDirection(Set<Direction> choices) {
61 List<Direction> choiceList = new ArrayList<>(choices);
62 return choiceList.get(RANDOM_SOURCE.nextInt(choices.size()));
63 }
64
65 /**
66 * Moves according to an improved version of a <i>random walk</i> : the
67 * probabilistic animal does not directly retrace its steps if not forced.
68 */
69 @Override
70 public Direction move(Set<Direction> choices) {
71 if (choices.isEmpty()) return Direction.NONE;
72
73 Set<Direction> smartChoices = choices.size() > 1 ? this.excludeOrigin(choices) : choices;
74 return this.getRandomDirection(smartChoices);
75 }
76
77}