All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.almasb.fxgl.pathfinding.heuristic.ManhattanDistance Maven / Gradle / Ivy

The newest version!
/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB ([email protected]).
 * See LICENSE for details.
 */

package com.almasb.fxgl.pathfinding.heuristic;

import com.almasb.fxgl.core.collection.grid.Cell;

import static java.lang.Math.*;

/**
 * See https://en.wikipedia.org/wiki/Taxicab_geometry for definition.
 *
 * @author Jean-René Lavoie ([email protected])
 */
public final class ManhattanDistance extends Heuristic {

    public ManhattanDistance() {
        super();
    }

    public ManhattanDistance(int weight) {
        super(weight);
    }

    @Override
    public int getCost(int startX, int startY, int targetX, int targetY) {
        return (abs(targetX - startX) + abs(targetY - startY)) * getWeight();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy