X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=blobdiff_plain;f=extra%2Fpath-finding%2Fpath-finding.factor;h=e5048da6f762da854511532352c85be78ad775b8;hp=7f621ef5f4e37ad950d56e8121b5e326fb2fba4e;hb=6d4293b5822d769619f66e46e64b704ddfe41b43;hpb=b7bb69b178712e9d135362ebd6efa69c9b8371ba diff --git a/extra/path-finding/path-finding.factor b/extra/path-finding/path-finding.factor index 7f621ef5f4..e5048da6f7 100644 --- a/extra/path-finding/path-finding.factor +++ b/extra/path-finding/path-finding.factor @@ -8,7 +8,7 @@ IN: path-finding TUPLE: astar g in-closed-set ; GENERIC: cost ( from to astar -- n ) GENERIC: heuristic ( from to astar -- n ) -GENERIC: neighbours ( node astar -- seq ) +GENERIC: neighbors ( node astar -- seq ) > at ] keep ] dip ] produce 2nip reverse ; : handle ( node astar -- ) - dupd [ astar>> neighbours ] keep [ ?set-g ] curry with each ; + dupd [ astar>> neighbors ] keep [ ?set-g ] curry with each ; : (find-path) ( astar -- path/f ) dup open-set>> heap-empty? [ @@ -64,34 +64,34 @@ TUPLE: (astar) astar goal origin in-open-set open-set ; >>open-set [ 0 ] 2dip [ (add-to-open-set) ] [ astar>> g>> set-at ] 3bi ; -TUPLE: astar-simple < astar cost heuristic neighbours ; +TUPLE: astar-simple < astar cost heuristic neighbors ; M: astar-simple cost cost>> call( n1 n2 -- c ) ; M: astar-simple heuristic heuristic>> call( n1 n2 -- c ) ; -M: astar-simple neighbours neighbours>> call( n -- neighbours ) ; +M: astar-simple neighbors neighbours>> call( n -- neighbours ) ; -TUPLE: bfs < astar neighbours ; +TUPLE: bfs < astar neighbors ; M: bfs cost 3drop 1 ; M: bfs heuristic 3drop 0 ; -M: bfs neighbours neighbours>> at ; +M: bfs neighbors neighbours>> at ; TUPLE: dijkstra < astar costs ; M: dijkstra cost costs>> swapd at at ; M: dijkstra heuristic 3drop 0 ; -M: dijkstra neighbours costs>> at keys ; +M: dijkstra neighbors costs>> at keys ; PRIVATE> : find-path ( start target astar -- path/f ) (astar) new [ astar<< ] keep [ (init) ] [ (find-path) ] bi ; -: ( neighbours cost heuristic -- astar ) - astar-simple new swap >>heuristic swap >>cost swap >>neighbours ; +: ( neighbors cost heuristic -- astar ) + astar-simple new swap >>heuristic swap >>cost swap >>neighbors ; : considered ( astar -- considered ) in-closed-set>> members ; -: ( neighbours -- astar ) - [ bfs new ] dip >>neighbours ; +: ( neighbors -- astar ) + [ bfs new ] dip >>neighbors ; : ( costs -- astar ) [ dijkstra new ] dip >>costs ;