-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (36 loc) · 795 Bytes
/
main.go
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
package main
import (
"fmt"
"github.com/shanghuiyang/astar"
"github.com/shanghuiyang/astar/tilemap"
)
// a map with 10 rows and 20 cols
const strmap = `
####################
# #
# #
# ######### #
# #
# ####### #
# #
# #
# #
####################
`
func main() {
// build a map from string
m := tilemap.BuildFromStr(strmap)
// define the origin and destination
org := &astar.Point{X: 7, Y: 2}
des := &astar.Point{X: 1, Y: 16}
// find the path using a-star algorithm
a := astar.New(m)
path, err := a.FindPath(org, des)
if err != nil {
fmt.Printf("error: %v\n", err)
return
}
// draw the tilemap with the path
a.Draw()
fmt.Printf("path: %v\n\n", path)
}