summaryrefslogtreecommitdiff
path: root/src/ch
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-11-23 12:01:02 +0100
committerPacien TRAN-GIRARD2015-11-23 12:01:02 +0100
commita842d134397747a0f72d2f70ca604c28784d05a3 (patch)
tree998d51101ad8a79bfdce9f51b07c0b1c90eeba04 /src/ch
parent3bac5786bf9d14854d90843cb6bc7317afffc810 (diff)
downloadmaze-solver-a842d134397747a0f72d2f70ca604c28784d05a3.tar.gz
Implement Clyde A.I.
Diffstat (limited to 'src/ch')
-rw-r--r--src/ch/epfl/maze/physical/GhostPredator.java11
-rw-r--r--src/ch/epfl/maze/physical/pacman/Clyde.java46
2 files changed, 49 insertions, 8 deletions
diff --git a/src/ch/epfl/maze/physical/GhostPredator.java b/src/ch/epfl/maze/physical/GhostPredator.java
index 44bb1f6..8188c00 100644
--- a/src/ch/epfl/maze/physical/GhostPredator.java
+++ b/src/ch/epfl/maze/physical/GhostPredator.java
@@ -188,13 +188,22 @@ abstract public class GhostPredator extends Predator {
188 } 188 }
189 189
190 /** 190 /**
191 * Returns the current Mode.
192 *
193 * @return The current Mode
194 */
195 protected Mode getMode(Daedalus daedalus) {
196 return this.mode;
197 }
198
199 /**
191 * Returns the position to target according to the current Mode. 200 * Returns the position to target according to the current Mode.
192 * 201 *
193 * @param daedalus The Daedalus 202 * @param daedalus The Daedalus
194 * @return The position to target 203 * @return The position to target
195 */ 204 */
196 protected Vector2D getTargetPosition(Daedalus daedalus) { 205 protected Vector2D getTargetPosition(Daedalus daedalus) {
197 switch (this.mode) { 206 switch (this.getMode(daedalus)) {
198 case CHASE: 207 case CHASE:
199 return this.getPreyTargetPosition(daedalus); 208 return this.getPreyTargetPosition(daedalus);
200 case SCATTER: 209 case SCATTER:
diff --git a/src/ch/epfl/maze/physical/pacman/Clyde.java b/src/ch/epfl/maze/physical/pacman/Clyde.java
index 6b3bef3..7e8bdd7 100644
--- a/src/ch/epfl/maze/physical/pacman/Clyde.java
+++ b/src/ch/epfl/maze/physical/pacman/Clyde.java
@@ -3,35 +3,67 @@ package ch.epfl.maze.physical.pacman;
3import ch.epfl.maze.physical.Animal; 3import ch.epfl.maze.physical.Animal;
4import ch.epfl.maze.physical.Daedalus; 4import ch.epfl.maze.physical.Daedalus;
5import ch.epfl.maze.physical.GhostPredator; 5import ch.epfl.maze.physical.GhostPredator;
6import ch.epfl.maze.util.Direction;
7import ch.epfl.maze.util.Vector2D; 6import ch.epfl.maze.util.Vector2D;
8 7
9/** 8/**
10 * Orange ghost from the Pac-Man game, alternates between direct chase if far 9 * Orange ghost from the Pac-Man game, alternates between direct chase if far
11 * from its target and SCATTER if close. 10 * from its target and SCATTER if close.
11 *
12 * @author Pacien TRAN-GIRARD
12 */ 13 */
13
14public class Clyde extends GhostPredator { 14public class Clyde extends GhostPredator {
15 15
16 private static double PROXIMITY_THRESHOLD = 4.0d;
17
16 /** 18 /**
17 * Constructs a Clyde with a starting position. 19 * Constructs a Clyde with a starting position.
18 * 20 *
19 * @param position Starting position of Clyde in the labyrinth 21 * @param position Starting position of Clyde in the labyrinth
20 */ 22 */
21
22 public Clyde(Vector2D position) { 23 public Clyde(Vector2D position) {
23 super(position); 24 super(position);
24 // TODO
25 } 25 }
26 26
27 /**
28 * Checks if Clyde is close to the targeted Prey.
29 *
30 * @param daedalus The Daedalus
31 * @return T(the Prey is reckless)
32 */
33 private boolean closeToTarget(Daedalus daedalus) {
34 double dist = this
35 .getPosition()
36 .sub(this.getPreyPosition(daedalus))
37 .dist();
38
39 return dist < Clyde.PROXIMITY_THRESHOLD;
40 }
41
42 /**
43 * Returns the current Mode, forcing the SCATTER Mode if far from the target.
44 *
45 * @param daedalus The Daedalus
46 * @return The current Mode
47 */
27 @Override 48 @Override
28 public Direction move(Direction[] choices, Daedalus daedalus) { 49 protected Mode getMode(Daedalus daedalus) {
29 // TODO 50 return this.closeToTarget(daedalus) ? super.getMode(daedalus) : Mode.SCATTER;
30 return Direction.NONE; 51 }
52
53 /**
54 * Targets directly the current position of the Prey.
55 *
56 * @param daedalus The Daedalus
57 * @return The position of the Prey
58 */
59 @Override
60 protected Vector2D getPreyTargetPosition(Daedalus daedalus) {
61 return getPreyPosition(daedalus);
31 } 62 }
32 63
33 @Override 64 @Override
34 public Animal copy() { 65 public Animal copy() {
35 return new Clyde(this.getPosition()); 66 return new Clyde(this.getPosition());
36 } 67 }
68
37} 69}