author David Thompson Tue, 2 Oct 2018 21:12:44 +0000 (17:12 -0400) committer David Thompson Wed, 3 Oct 2018 11:45:33 +0000 (07:45 -0400)
 Makefile.am patch | blob | blame | history chickadee/math/path-finding.scm [moved from chickadee/path-finding.scm with 88% similarity] patch | blob | blame | history

index 1ae2d24..2b27ba2 100644 (file)
@@ -53,6 +53,7 @@ SOURCES =                                     \
@@ -73,7 +74,6 @@ SOURCES =                                     \

similarity index 88%
index 9af01f8..d89c2fc 100644 (file)
@@ -20,7 +20,7 @@
;;
;;; Code

+(define-module (chickadee math path-finding)
#:use-module (srfi srfi-9)
#:export (make-path-finder
(make-hash-table)
(make-hash-table)))

-(define (a* path-finder start goal neighbors cost heuristic)
+(define (a* path-finder start goal neighbors cost distance)
"Return a list of nodes forming a path from START to GOAL using
PATH-FINDER.  NEIGHBORS is a procedure that accepts a node and returns
a list of nodes that neighbor it.  COST is a procedure that accepts
-two neighboring nodes and the cost of moving from the first to the
-second as a number.  HEURISTIC is a procedure that accepts two nodes
-and returns an approximate distance between them."
+two neighboring nodes and returns the cost of moving from the first to
+the second as a number.  DISTANCE is a procedure that accepts two
+nodes and returns an approximate distance between them."
(let ((frontier (path-finder-frontier path-finder))
(came-from (path-finder-came-from path-finder))
(cost-so-far (path-finder-cost-so-far path-finder)))
@@ -64,7 +64,7 @@ and returns an approximate distance between them."
(when (or (not (hashq-ref cost-so-far next))
(< new-cost (hashq-ref cost-so-far next)))
(hashq-set! cost-so-far next new-cost)
-                            (let ((priority (+ new-cost (heuristic goal next))))
+                            (let ((priority (+ new-cost (distance goal next))))
(heap-insert! frontier (cons next priority)))
(hashq-set! came-from next current))))
(neighbors current))