summaryrefslogtreecommitdiff
path: root/src/ch/epfl
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-11-22 16:48:50 +0100
committerPacien TRAN-GIRARD2015-11-22 16:48:50 +0100
commit62b603d3d74bdeff56811fae08e4f47136b7aea2 (patch)
treef7dbd95dc3c71425de4421fd14b41aec42f1f7e0 /src/ch/epfl
parent15c612d56c98849daafeebea79d3f8f9b3a887b2 (diff)
downloadmaze-solver-62b603d3d74bdeff56811fae08e4f47136b7aea2.tar.gz
Implement Daedalus
Diffstat (limited to 'src/ch/epfl')
-rw-r--r--src/ch/epfl/maze/physical/Daedalus.java64
1 files changed, 36 insertions, 28 deletions
diff --git a/src/ch/epfl/maze/physical/Daedalus.java b/src/ch/epfl/maze/physical/Daedalus.java
index 2edad7b..8018b66 100644
--- a/src/ch/epfl/maze/physical/Daedalus.java
+++ b/src/ch/epfl/maze/physical/Daedalus.java
@@ -2,29 +2,41 @@ package ch.epfl.maze.physical;
2 2
3import java.util.ArrayList; 3import java.util.ArrayList;
4import java.util.List; 4import java.util.List;
5import java.util.stream.Collectors;
6import java.util.stream.Stream;
5 7
6/** 8/**
7 * Daedalus in which predators hunt preys. Once a prey has been caught by a 9 * Daedalus in which predators hunt preys. Once a prey has been caught by a
8 * predator, it will be removed from the daedalus. 10 * predator, it will be removed from the daedalus.
11 *
12 * @author Pacien TRAN-GIRARD
9 */ 13 */
10
11public final class Daedalus extends World { 14public final class Daedalus extends World {
12 15
16 private final List<Predator> predators;
17 private final List<Predator> predatorHistory;
18
19 private final List<Prey> preys;
20 private final List<Prey> preyHistory;
21
13 /** 22 /**
14 * Constructs a Daedalus with a labyrinth structure 23 * Constructs a Daedalus with a labyrinth structure
15 * 24 *
16 * @param labyrinth Structure of the labyrinth, an NxM array of tiles 25 * @param labyrinth Structure of the labyrinth, an NxM array of tiles
17 */ 26 */
18
19 public Daedalus(int[][] labyrinth) { 27 public Daedalus(int[][] labyrinth) {
20 super(labyrinth); 28 super(labyrinth);
21 // TODO 29
30 this.predators = new ArrayList<>();
31 this.predatorHistory = new ArrayList<>();
32
33 this.preys = new ArrayList<>();
34 this.preyHistory = new ArrayList<>();
22 } 35 }
23 36
24 @Override 37 @Override
25 public boolean isSolved() { 38 public boolean isSolved() {
26 // TODO 39 return this.preys.isEmpty();
27 return false;
28 } 40 }
29 41
30 /** 42 /**
@@ -32,9 +44,9 @@ public final class Daedalus extends World {
32 * 44 *
33 * @param p The predator to add 45 * @param p The predator to add
34 */ 46 */
35
36 public void addPredator(Predator p) { 47 public void addPredator(Predator p) {
37 // TODO 48 this.predators.add(p);
49 this.predatorHistory.add((Predator) p.copy());
38 } 50 }
39 51
40 /** 52 /**
@@ -42,9 +54,9 @@ public final class Daedalus extends World {
42 * 54 *
43 * @param p The prey to add 55 * @param p The prey to add
44 */ 56 */
45
46 public void addPrey(Prey p) { 57 public void addPrey(Prey p) {
47 // TODO 58 this.preys.add(p);
59 this.preyHistory.add((Prey) p.copy());
48 } 60 }
49 61
50 /** 62 /**
@@ -52,9 +64,8 @@ public final class Daedalus extends World {
52 * 64 *
53 * @param p The predator to remove 65 * @param p The predator to remove
54 */ 66 */
55
56 public void removePredator(Predator p) { 67 public void removePredator(Predator p) {
57 // TODO 68 this.predators.remove(p);
58 } 69 }
59 70
60 /** 71 /**
@@ -62,15 +73,15 @@ public final class Daedalus extends World {
62 * 73 *
63 * @param p The prey to remove 74 * @param p The prey to remove
64 */ 75 */
65
66 public void removePrey(Prey p) { 76 public void removePrey(Prey p) {
67 // TODO 77 this.preys.remove(p);
68 } 78 }
69 79
70 @Override 80 @Override
71 public List<Animal> getAnimals() { 81 public List<Animal> getAnimals() {
72 // TODO 82 return Stream
73 return null; 83 .concat(this.predators.stream(), this.preys.stream())
84 .collect(Collectors.toList());
74 } 85 }
75 86
76 /** 87 /**
@@ -78,10 +89,8 @@ public final class Daedalus extends World {
78 * 89 *
79 * @return A list of all predators in the daedalus 90 * @return A list of all predators in the daedalus
80 */ 91 */
81
82 public List<Predator> getPredators() { 92 public List<Predator> getPredators() {
83 // TODO 93 return this.predators;
84 return new ArrayList<Predator>();
85 } 94 }
86 95
87 /** 96 /**
@@ -89,10 +98,8 @@ public final class Daedalus extends World {
89 * 98 *
90 * @return A list of all preys in the daedalus 99 * @return A list of all preys in the daedalus
91 */ 100 */
92
93 public List<Prey> getPreys() { 101 public List<Prey> getPreys() {
94 // TODO 102 return this.preys;
95 return new ArrayList<Prey>();
96 } 103 }
97 104
98 /** 105 /**
@@ -102,10 +109,8 @@ public final class Daedalus extends World {
102 * @return <b>true</b> if the predator belongs to the world, <b>false</b> 109 * @return <b>true</b> if the predator belongs to the world, <b>false</b>
103 * otherwise. 110 * otherwise.
104 */ 111 */
105
106 public boolean hasPredator(Predator p) { 112 public boolean hasPredator(Predator p) {
107 // TODO 113 return this.predators.contains(p);
108 return false;
109 } 114 }
110 115
111 /** 116 /**
@@ -115,14 +120,17 @@ public final class Daedalus extends World {
115 * @return <b>true</b> if the prey belongs to the world, <b>false</b> 120 * @return <b>true</b> if the prey belongs to the world, <b>false</b>
116 * otherwise. 121 * otherwise.
117 */ 122 */
118
119 public boolean hasPrey(Prey p) { 123 public boolean hasPrey(Prey p) {
120 // TODO 124 return this.preys.contains(p);
121 return false;
122 } 125 }
123 126
124 @Override 127 @Override
125 public void reset() { 128 public void reset() {
126 // TODO 129 this.predators.clear();
130 this.predators.addAll(this.predatorHistory);
131
132 this.preys.clear();
133 this.preys.addAll(this.preyHistory);
127 } 134 }
135
128} 136}