https://github.com/beefsack/go-astar
有完整的測試案例,代碼全面性最好。
實現在 https://github.com/beefsack/go-astar/blob/master/astar.go
集成 open 和 close 在node類,然后用map管理這個node類****
// node is a wrapper to store A* data for a Pather node.
type node struct {
pather Pather
cost float64
rank float64
parent *node
open bool
closed bool
index int
}
// nodeMap is a collection of nodes keyed by Pather nodes for quick reference.
type nodeMap map[Pather]*node
https://github.com/nickdavies/go-astar
推薦用這個。
使用map管理open、close列表
相關代碼在:https://github.com/nickdavies/go-astar/blob/master/astar/astar.go
var openList = make(map[Point]*PathPoint)
var closeList = make(map[Point]*PathPoint)
同時實現一個尋找map中最小權重的節點函數
func (a *gridStruct) getMinWeight(openList map[Point]*PathPoint) *PathPoint {
var min *PathPoint = nil
var minWeight int = 0
for _, p := range openList {
if min == nil || p.Weight < minWeight {
min = p
minWeight = p.Weight
}
}
return min
}
https://github.com/towski/Golang-AStar
用數組管理
https://github.com/towski/Golang-AStar/blob/master/utils/utils.go
var openList, closeList, path []Point
存在檢查、查找都是用了數組遍歷。
github.com/fzipp/astar
close隊列使用的是map, open隊列使用的優先隊列
closed := make(map[Node]bool)
pq := &priorityQueue{}
heap.Init(pq)
heap.Push(pq, &item{value: newPath(start)})
open 列表找最小沒找到實現代碼。