RuneHive-Game
Loading...
Searching...
No Matches
Chebyshev.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 Chebyshev heuristic, ideal for a system that allows for 8-directional movement.
7 * @author Artem Batutin <artembatutin@gmail.com>
8 */
9public final class Chebyshev implements Distance {
10
11 @Override
12 public int calculate(Position to, Position from) {
13 int dx = Math.abs(from.getX() - to.getX());
14 int dy = Math.abs(from.getX() - to.getY());
15 return dx >= dy ? dx : dy;
16 }
17}
int calculate(Position to, Position from)
Calculates the heuristic value of the defined two positions.
The Chebyshev heuristic, ideal for a system that allows for 8-directional movement.
Definition Distance.java:28
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