From e9acb9330ad2fed4235b0270d67d1ee1ac9d2005 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 23 Nov 2015 11:43:49 +0100 Subject: Implement Pinky A.I. --- src/ch/epfl/maze/physical/pacman/Pinky.java | 35 ++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'src/ch') diff --git a/src/ch/epfl/maze/physical/pacman/Pinky.java b/src/ch/epfl/maze/physical/pacman/Pinky.java index 3e4209d..ebabc15 100644 --- a/src/ch/epfl/maze/physical/pacman/Pinky.java +++ b/src/ch/epfl/maze/physical/pacman/Pinky.java @@ -6,31 +6,54 @@ import ch.epfl.maze.physical.GhostPredator; import ch.epfl.maze.util.Direction; import ch.epfl.maze.util.Vector2D; +import java.util.Vector; + /** * Pink ghost from the Pac-Man game, targets 4 squares in front of its target. + * + * @author Pacien TRAN-GIRARD */ - public class Pinky extends GhostPredator { + private static final int TARGET_OFFSET = 4; /** * Constructs a Pinky with a starting position. * * @param position Starting position of Pinky in the labyrinth */ - public Pinky(Vector2D position) { super(position); - // TODO } + /** + * Targets the position the Prey is heading toward. + * + * @param daedalus The Daedalus + * @return The projected position + */ @Override - public Direction move(Direction[] choices, Daedalus daedalus) { - // TODO - return Direction.NONE; + protected Vector2D getPreyTargetPosition(Daedalus daedalus) { + Vector2D offsetVector = this.getTargetOffsetVector(this.getPreyDirection(daedalus)); + return this + .getPreyPosition(daedalus) + .add(offsetVector); + } + + /** + * Returns the offset vector directed to the given Direction. + * + * @param direction The Direction + * @return The offset Vector2D + */ + private Vector2D getTargetOffsetVector(Direction direction) { + return (new Vector2D()) + .addDirectionTo(direction) + .mul(TARGET_OFFSET); } @Override public Animal copy() { return new Pinky(this.getPosition()); } + } -- cgit v1.2.3