Move pathfinding module to math directory.
authorDavid Thompson <dthompson2@worcester.edu>
Tue, 2 Oct 2018 21:12:44 +0000 (17:12 -0400)
committerDavid Thompson <dthompson2@worcester.edu>
Wed, 3 Oct 2018 11:45:33 +0000 (07:45 -0400)
Makefile.am
chickadee/math/path-finding.scm [moved from chickadee/path-finding.scm with 88% similarity]

index 1ae2d24..2b27ba2 100644 (file)
@@ -53,6 +53,7 @@ SOURCES =                                     \
   chickadee/math/rect.scm                      \
   chickadee/math/grid.scm                      \
   chickadee/math/easings.scm                   \
+  chickadee/math/path-finding.scm              \
   chickadee/render/color.scm                   \
   chickadee/render/gl.scm                      \
   chickadee/render/gpu.scm                     \
@@ -73,7 +74,6 @@ SOURCES =                                     \
   chickadee/scripting/script.scm               \
   chickadee/scripting/channel.scm              \
   chickadee/scripting.scm                      \
-  chickadee/path-finding.scm                   \
   chickadee.scm                                        \
   chickadee/sdl.scm
 
similarity index 88%
rename from chickadee/path-finding.scm
rename to chickadee/math/path-finding.scm
index 9af01f8..d89c2fc 100644 (file)
@@ -20,7 +20,7 @@
 ;;
 ;;; Code
 
-(define-module (chickadee path-finding)
+(define-module (chickadee math path-finding)
   #:use-module (chickadee heap)
   #: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))