Created
December 15, 2022 07:00
-
-
Save deleteman/2b6f1cb70c42cf7f70e87c8aa3ee6ff5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function heuristic(state) { | |
// Calculate the number of steps required to reach the goal, using the Manhattan distance formula | |
let dx = Math.abs(state.x - goal.x); | |
let dy = Math.abs(state.y - goal.y); | |
let penalty = pathIntersectsObstacle(state, goal, obstacles) * 10 | |
return Math.sqrt(dx*dx + dy * dy) + penalty; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment