diff options
Diffstat (limited to 'src/ch/epfl/maze/physical/zoo/Hamster.java')
-rw-r--r-- | src/ch/epfl/maze/physical/zoo/Hamster.java | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/ch/epfl/maze/physical/zoo/Hamster.java b/src/ch/epfl/maze/physical/zoo/Hamster.java index 27706a5..3c903f5 100644 --- a/src/ch/epfl/maze/physical/zoo/Hamster.java +++ b/src/ch/epfl/maze/physical/zoo/Hamster.java | |||
@@ -6,7 +6,9 @@ import ch.epfl.maze.util.Direction; | |||
6 | import ch.epfl.maze.util.Vector2D; | 6 | import ch.epfl.maze.util.Vector2D; |
7 | 7 | ||
8 | import java.util.ArrayList; | 8 | import java.util.ArrayList; |
9 | import java.util.Arrays; | ||
9 | import java.util.List; | 10 | import java.util.List; |
11 | import java.util.stream.Collectors; | ||
10 | 12 | ||
11 | /** | 13 | /** |
12 | * Hamster A.I. that remembers the previous choice it has made and the dead ends | 14 | * Hamster A.I. that remembers the previous choice it has made and the dead ends |
@@ -38,13 +40,11 @@ public class Hamster extends ProbabilisticAnimal { | |||
38 | */ | 40 | */ |
39 | 41 | ||
40 | private Direction[] excludeDeadPaths(Direction[] choices) { | 42 | private Direction[] excludeDeadPaths(Direction[] choices) { |
41 | List<Direction> smartChoices = new ArrayList<>(); | 43 | return (new ArrayList<>(Arrays.asList(choices))) |
42 | 44 | .stream() | |
43 | for (Direction dir : choices) | 45 | .filter(dir -> !this.deadPaths.contains(this.getPosition().addDirectionTo(dir))) |
44 | if (!this.deadPaths.contains(this.getPosition().addDirectionTo(dir))) | 46 | .collect(Collectors.toList()) |
45 | smartChoices.add(dir); | 47 | .toArray(new Direction[0]); |
46 | |||
47 | return smartChoices.toArray(new Direction[smartChoices.size()]); | ||
48 | } | 48 | } |
49 | 49 | ||
50 | /** | 50 | /** |