Skip to content

Instantly share code, notes, and snippets.

@deleteman
Created December 15, 2022 07:00
Show Gist options
  • Save deleteman/2b6f1cb70c42cf7f70e87c8aa3ee6ff5 to your computer and use it in GitHub Desktop.
Save deleteman/2b6f1cb70c42cf7f70e87c8aa3ee6ff5 to your computer and use it in GitHub Desktop.
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