@nichathan-gaming/map-generator
Version:
Creates and generates a 2 dimensional array with various path generation functions.
16 lines (13 loc) • 574 B
JavaScript
import assertIndex from "../helpers/assertIndex.js";
/**
* Gets the distance from the index to the goal
* @param {[number, number]} currentIndex The index that we are looking at
* @param {[number, number]} endingIndex The index that we are moving towards
* @returns {number} The distance to the goal
*/
const getCostToGoal = (currentIndex, endingIndex) => {
assertIndex(currentIndex);
assertIndex(endingIndex);
return Math.abs(currentIndex[0] - endingIndex[0]) + Math.abs(currentIndex[1] - endingIndex[1]);
};
export default getCostToGoal;