From c5e5646b7785e1b5d1c46efd5e93a6f95d5bad9f Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Wed, 25 Nov 2015 00:07:56 +0100 Subject: Implement PacMan predator avoidance --- .../stragegies/planner/DistanceCalculator.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/ch/epfl/maze/physical/stragegies/planner/DistanceCalculator.java (limited to 'src/ch/epfl/maze/physical/stragegies/planner') diff --git a/src/ch/epfl/maze/physical/stragegies/planner/DistanceCalculator.java b/src/ch/epfl/maze/physical/stragegies/planner/DistanceCalculator.java new file mode 100644 index 0000000..daeb581 --- /dev/null +++ b/src/ch/epfl/maze/physical/stragegies/planner/DistanceCalculator.java @@ -0,0 +1,33 @@ +package ch.epfl.maze.physical.stragegies.planner; + +import ch.epfl.maze.util.Direction; +import ch.epfl.maze.util.Vector2D; + +/** + * @author Pacien TRAN-GIRARD + */ +public interface DistanceCalculator { + + /** + * Returns the current position. + * + * @return The current position vector + */ + Vector2D getPosition(); + + /** + * Calculates the Euclidean distance from the adjacent position at the given Direction to the target position. + * + * @param dir The adjacent Direction + * @param targetPosition The targeted position + * @return The Euclidean distance between the two positions + */ + default double getDistanceTo(Direction dir, Vector2D targetPosition) { + return this + .getPosition() + .addDirectionTo(dir) + .sub(targetPosition) + .dist(); + } + +} -- cgit v1.2.3