RuneHive-Game
Loading...
Searching...
No Matches
Manhattan.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 * The Manhattan Distance is the distance between two points measured along axes
7 * at right angles. The name alludes to the grid layout of the streets of
8 * Manhattan, which causes the shortest path a car could take between two points
9 * in the city. Perfect for 4 dimensional movements.
10 *
11 * @author Artem Batutin <artembatutin@gmail.com>
12 */
13public class Manhattan implements Distance {
14
15 @Override
16 public int calculate(Position to, Position from) {
17 int deltaX = Math.abs(from.getX() - to.getX());
18 int deltaY = Math.abs(from.getY() - to.getY());
19 return deltaX + deltaY;
20 }
21
22}
The Manhattan Distance is the distance between two points measured along axes at right angles.
Definition Distance.java:64
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