RuneHive-Game
Loading...
Searching...
No Matches
Euclidean.java
Go to the documentation of this file.
1package com.runehive.game.world.pathfinding.distance;
2
3import com.runehive.game.world.position.Position;
4
5/**
6 * Since Euclidean distance is shorter than Manhattan or diagonal distance, you will still get shortest paths,
7 * but the pathfinder will take longer to run.
8 * @author Artem Batutin <artembatutin@gmail.com>
9 */
10public class Euclidean implements Distance {
11
12 @Override
13 public int calculate(Position to, Position from) {
14 int deltaX = from.getX() - to.getX();
15 int deltaY = from.getY() - to.getY();
16 return (int) Math.sqrt(deltaX * deltaX + deltaY * deltaY);
17 }
18
19}
Since Euclidean distance is shorter than Manhattan or diagonal distance, you will still get shortest ...
Definition Distance.java:45
int calculate(Position to, Position from)
Calculates the heuristic value of the defined two positions.
Represents a single tile on the game world.
Definition Position.java:14
int getY()
Gets the absolute y coordinate.
Definition Position.java:46
int getX()
Gets the absolute x coordinate.
Definition Position.java:41
An interface to calculate the distance between two nodes in a Position.
Definition Distance.java:11