A port of EasyStar.js to the Go programming language.
##Installation
go get github.com/prettymuchbryce/goeasystar
##Documentation GoDoc
easystar := goeasystar.NewPathfinder()
easystar.SetGrid(grid [][]int)
easystar.SetAcceptableTiles(t []int)`
easystar.FindPath(startX, startY, endX, endY) ([]*goeasystar.Point, error)
-
Avoiding additional points (outside of acceptable tiles)
-
Diagonals
-
Corner cutting
-
Setting costs per-tile
-
Setting additional point costs (outside of tile costs)
First create an instance of the Pathfinder.
easystar := NewPathfinder()
Create a grid, or tilemap. You may have made this with a level editor, or procedurally. Let's keep it simple for this example.
var grid [][]int
grid = append(grid, []int{1, 0, 0, 0, 0})
grid = append(grid, []int{0, 1, 0, 0, 0})
grid = append(grid, []int{0, 0, 1, 0, 0})
grid = append(grid, []int{0, 0, 0, 1, 0})
grid = append(grid, []int{0, 0, 0, 0, 1})
Set our grid.
easystar.SetGrid(grid)
Set tiles which are "walkable".
easystar.SetAcceptableTiles([]int{1})
Find a path.
path, err := easystar.FindPath(0, 0, 4, 4)
fmt.Println(err == nil) // false
Oops. We didn't have diagonals enabled so there is no valid path. Lets try again.
easystar.EnableDiagonals()
path, err := easystar.FindPath(0, 0, 4, 4)
fmt.Println(err) // nil
len(path) // 4
goeasystar is licensed under the MIT license.
goeasystar uses facebookgo's pqueue which falls under the Apache 2 License.
I would be happy to eventually remove it in favor of an MIT-licensed priority queue implementation.
If you have any questions, comments, or suggestions please open an issue.