summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-11-21 21:04:28 +0100
committerPacien TRAN-GIRARD2015-11-21 21:04:28 +0100
commit78f0dd183821ef471c430ddb6cb0444b28eb1367 (patch)
treeddcdd024e327ee4515da1f9af6d0f4956dcb6121 /src/ch/epfl/maze
parent71342b11dab1ed49e611292849107a6eb9c41a67 (diff)
downloadmaze-solver-78f0dd183821ef471c430ddb6cb0444b28eb1367.tar.gz
Use more explicit stream filters
Diffstat (limited to 'src/ch/epfl/maze')
-rw-r--r--src/ch/epfl/maze/physical/zoo/Hamster.java14
-rw-r--r--src/ch/epfl/maze/physical/zoo/Mouse.java15
2 files changed, 14 insertions, 15 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;
6import ch.epfl.maze.util.Vector2D; 6import ch.epfl.maze.util.Vector2D;
7 7
8import java.util.ArrayList; 8import java.util.ArrayList;
9import java.util.Arrays;
9import java.util.List; 10import java.util.List;
11import 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 /**
diff --git a/src/ch/epfl/maze/physical/zoo/Mouse.java b/src/ch/epfl/maze/physical/zoo/Mouse.java
index 1b22c66..b5483c1 100644
--- a/src/ch/epfl/maze/physical/zoo/Mouse.java
+++ b/src/ch/epfl/maze/physical/zoo/Mouse.java
@@ -6,7 +6,8 @@ import ch.epfl.maze.util.Direction;
6import ch.epfl.maze.util.Vector2D; 6import ch.epfl.maze.util.Vector2D;
7 7
8import java.util.ArrayList; 8import java.util.ArrayList;
9import java.util.List; 9import java.util.Arrays;
10import java.util.stream.Collectors;
10 11
11/** 12/**
12 * Mouse A.I. that remembers only the previous choice it has made. 13 * Mouse A.I. that remembers only the previous choice it has made.
@@ -37,13 +38,11 @@ public class Mouse extends ProbabilisticAnimal {
37 */ 38 */
38 39
39 private Direction[] excludeOrigin(Direction[] choices) { 40 private Direction[] excludeOrigin(Direction[] choices) {
40 List<Direction> smartChoices = new ArrayList<>(choices.length - 1); // max size, excluding origin 41 return (new ArrayList<>(Arrays.asList(choices)))
41 42 .stream()
42 for (Direction dir : choices) 43 .filter(dir -> !dir.isOpposite(this.previousChoice))
43 if (!dir.isOpposite(this.previousChoice)) 44 .collect(Collectors.toList())
44 smartChoices.add(dir); 45 .toArray(new Direction[0]);
45
46 return smartChoices.toArray(new Direction[smartChoices.size()]);
47 } 46 }
48 47
49 /** 48 /**