summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/zoo/Mouse.java
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/physical/zoo/Mouse.java
parent71342b11dab1ed49e611292849107a6eb9c41a67 (diff)
downloadmaze-solver-78f0dd183821ef471c430ddb6cb0444b28eb1367.tar.gz
Use more explicit stream filters
Diffstat (limited to 'src/ch/epfl/maze/physical/zoo/Mouse.java')
-rw-r--r--src/ch/epfl/maze/physical/zoo/Mouse.java15
1 files changed, 7 insertions, 8 deletions
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 /**