-
Notifications
You must be signed in to change notification settings - Fork 0
/
a-star.lsp
53 lines (43 loc) · 1.46 KB
/
a-star.lsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
;; ---------------- a star search --------------
;;; fill the table with the nodes and the struct as the list for the
;;; a star algorithm
(defstruct node
attached
g_score
came_from
)
(defun makeStructs ()
)
(defun astar (start goal heuristic)
(setf closedset ())
(setf openset ()) ;; get all the nodes that are in the hashmap
(makeStructs)
(setf g_score 0)
(setf f_score (+ g_score heuristic))
(loop while (> (length openset) 0)
(setf current) ;; having the lowest f_score value
(if (equal current goal)
(return (reconstruct_path))
)
(remove-if #'(lambda (x) (equal x current)) openset)
(append closedset (list current))
(loop for x in (getNodesConnected current) do
(if (not (null (find x closedset)))
(continue))
;; get the costs from the table
(setf tentativeGscore (+ g_score (getcost current x)))
(if (or (null (find x closedset)) (<= tentativeGscore (g_score x))) ;;; get from table
(
;;; do something with the came_from ???
;;; g_score(x) = tentativeGscore
;;; f_score(neighbor) = g_score(neighbour) + heiristic cost estimate(neighboard, goal)
(if (null (find x openset))
(append openset (list x))
)
)
() ;;; else part
)
)
)
(return "Failure")
)