From a842d134397747a0f72d2f70ca604c28784d05a3 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 23 Nov 2015 12:01:02 +0100 Subject: Implement Clyde A.I. --- src/ch/epfl/maze/physical/GhostPredator.java | 11 ++++++- src/ch/epfl/maze/physical/pacman/Clyde.java | 46 +++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 8 deletions(-) (limited to 'src') 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 @@ -187,6 +187,15 @@ abstract public class GhostPredator extends Predator { return this.move(bestPaths); } + /** + * Returns the current Mode. + * + * @return The current Mode + */ + protected Mode getMode(Daedalus daedalus) { + return this.mode; + } + /** * Returns the position to target according to the current Mode. * @@ -194,7 +203,7 @@ abstract public class GhostPredator extends Predator { * @return The position to target */ protected Vector2D getTargetPosition(Daedalus daedalus) { - switch (this.mode) { + switch (this.getMode(daedalus)) { case CHASE: return this.getPreyTargetPosition(daedalus); 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; import ch.epfl.maze.physical.Animal; import ch.epfl.maze.physical.Daedalus; import ch.epfl.maze.physical.GhostPredator; -import ch.epfl.maze.util.Direction; import ch.epfl.maze.util.Vector2D; /** * Orange ghost from the Pac-Man game, alternates between direct chase if far * from its target and SCATTER if close. + * + * @author Pacien TRAN-GIRARD */ - public class Clyde extends GhostPredator { + private static double PROXIMITY_THRESHOLD = 4.0d; + /** * Constructs a Clyde with a starting position. * * @param position Starting position of Clyde in the labyrinth */ - public Clyde(Vector2D position) { super(position); - // TODO } + /** + * Checks if Clyde is close to the targeted Prey. + * + * @param daedalus The Daedalus + * @return T(the Prey is reckless) + */ + private boolean closeToTarget(Daedalus daedalus) { + double dist = this + .getPosition() + .sub(this.getPreyPosition(daedalus)) + .dist(); + + return dist < Clyde.PROXIMITY_THRESHOLD; + } + + /** + * Returns the current Mode, forcing the SCATTER Mode if far from the target. + * + * @param daedalus The Daedalus + * @return The current Mode + */ @Override - public Direction move(Direction[] choices, Daedalus daedalus) { - // TODO - return Direction.NONE; + protected Mode getMode(Daedalus daedalus) { + return this.closeToTarget(daedalus) ? super.getMode(daedalus) : Mode.SCATTER; + } + + /** + * Targets directly the current position of the Prey. + * + * @param daedalus The Daedalus + * @return The position of the Prey + */ + @Override + protected Vector2D getPreyTargetPosition(Daedalus daedalus) { + return getPreyPosition(daedalus); } @Override public Animal copy() { return new Clyde(this.getPosition()); } + } -- cgit v1.2.3