summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/pacman/PacMan.java
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-11-25 00:07:56 +0100
committerPacien TRAN-GIRARD2015-11-25 00:07:56 +0100
commitc5e5646b7785e1b5d1c46efd5e93a6f95d5bad9f (patch)
treeeaa41d5e140f74c86b1d422c465919fc85ca0e6b /src/ch/epfl/maze/physical/pacman/PacMan.java
parent4da9bdc4fa2f44eedba3dff29af7b0ce9180e442 (diff)
downloadmaze-solver-c5e5646b7785e1b5d1c46efd5e93a6f95d5bad9f.tar.gz
Implement PacMan predator avoidance
Diffstat (limited to 'src/ch/epfl/maze/physical/pacman/PacMan.java')
-rw-r--r--src/ch/epfl/maze/physical/pacman/PacMan.java19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/ch/epfl/maze/physical/pacman/PacMan.java b/src/ch/epfl/maze/physical/pacman/PacMan.java
index e2a55e9..5458dd5 100644
--- a/src/ch/epfl/maze/physical/pacman/PacMan.java
+++ b/src/ch/epfl/maze/physical/pacman/PacMan.java
@@ -4,7 +4,8 @@ import ch.epfl.maze.physical.Animal;
4import ch.epfl.maze.physical.Daedalus; 4import ch.epfl.maze.physical.Daedalus;
5import ch.epfl.maze.physical.Prey; 5import ch.epfl.maze.physical.Prey;
6import ch.epfl.maze.physical.stragegies.picker.RandomPicker; 6import ch.epfl.maze.physical.stragegies.picker.RandomPicker;
7import ch.epfl.maze.physical.stragegies.reducer.BackwardReducer; 7import ch.epfl.maze.physical.stragegies.planner.DistanceCalculator;
8import ch.epfl.maze.physical.stragegies.reducer.CostReducer;
8import ch.epfl.maze.util.Direction; 9import ch.epfl.maze.util.Direction;
9import ch.epfl.maze.util.Vector2D; 10import ch.epfl.maze.util.Vector2D;
10 11
@@ -16,7 +17,7 @@ import java.util.Set;
16 * @author EPFL 17 * @author EPFL
17 * @author Pacien TRAN-GIRARD 18 * @author Pacien TRAN-GIRARD
18 */ 19 */
19public class PacMan extends Prey implements BackwardReducer, RandomPicker { 20public class PacMan extends Prey implements DistanceCalculator, CostReducer, RandomPicker {
20 21
21 /** 22 /**
22 * Constructs a new Pac-Man. 23 * Constructs a new Pac-Man.
@@ -28,8 +29,20 @@ public class PacMan extends Prey implements BackwardReducer, RandomPicker {
28 } 29 }
29 30
30 @Override 31 @Override
32 public int getChoiceCost(Direction choice, Daedalus daedalus) {
33 return (-1) * daedalus
34 .getPredatorSet()
35 .stream()
36 .map(pred -> this.getDistanceTo(choice, pred.getPosition()))
37 .map(dist -> dist * 100.0d)
38 .min(Double::compare)
39 .get()
40 .intValue();
41 }
42
43 @Override
31 public Direction move(Set<Direction> choices, Daedalus daedalus) { 44 public Direction move(Set<Direction> choices, Daedalus daedalus) {
32 Set<Direction> smartChoices = choices.size() > 1 ? this.reduce(choices) : choices; 45 Set<Direction> smartChoices = this.reduce(choices, daedalus);
33 return this.pick(smartChoices); 46 return this.pick(smartChoices);
34 } 47 }
35 48