diff options
author | Pacien TRAN-GIRARD | 2015-11-25 16:58:21 +0100 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2015-11-25 16:58:21 +0100 |
commit | c7bff348ec66e535a7146cf48907f4c8d785d623 (patch) | |
tree | 067dfd1c8e3c5a89acd842286750ab8a7400c324 /src/ch/epfl | |
parent | c5e5646b7785e1b5d1c46efd5e93a6f95d5bad9f (diff) | |
download | maze-solver-c7bff348ec66e535a7146cf48907f4c8d785d623.tar.gz |
Remove unused class
Diffstat (limited to 'src/ch/epfl')
-rw-r--r-- | src/ch/epfl/maze/physical/ProbabilisticAnimal.java | 77 |
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 @@ | |||
1 | package ch.epfl.maze.physical; | ||
2 | |||
3 | import ch.epfl.maze.util.Direction; | ||
4 | import ch.epfl.maze.util.Vector2D; | ||
5 | |||
6 | import java.util.ArrayList; | ||
7 | import java.util.List; | ||
8 | import java.util.Random; | ||
9 | import java.util.Set; | ||
10 | import 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 | */ | ||
17 | abstract 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 | } | ||