Created
July 29, 2011 10:17
-
-
Save jdoig/1113570 to your computer and use it in GitHub Desktop.
Generic Pathfinding implimentation
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
module Pathfinding | |
open Level | |
open Tools | |
(* a wrapper for mapPoint that can contain pathing data as per typical A* pathfinding *) | |
(* g = cost of path so far, h = estimated cost to goal, parent = tile we came here from *) | |
type PathingNode = | |
{point:MapPoint; h:float; g:float; parent:PathingNode option} | |
(* returns a pathnode based on a given map point *) | |
let pointToPathNode parent goal node = {point=node; h=node.Distance goal; g=(parent.g+1.0); parent=Some(parent)} | |
(* A 2D tile specific version of the A* algorithm *) | |
let pathFind | |
(map:Map) goal = aStar (fun n-> n.point) (fun n-> n.g) (fun n-> n.h) (fun n-> (map.GetNeighborsOf n.point) | |
|> List.filter(fun n-> n.value =0) | |
|> List.map (pointToPathNode n goal)) goal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment