Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Grid ¶
Grid is a 2D grid of any type.
func NewGridFromSlice ¶
NewGridFromSlice creates a new grid with the given width and height and fills it with the given slice.
type Option ¶
type Option func(o *option)
Option is a functional option for the pathfinder.
func EuclideanDistance ¶ added in v0.0.2
func EuclideanDistance() Option
EuclideanDistance sets the heuristic to Euclidean distance.
func PunishChangeDirection ¶
func PunishChangeDirection() Option
PunishChangeDirection punishes changing direction when calculating G.
func WithDiagonals ¶
func WithDiagonals() Option
WithDiagonals enables diagonal movement in the search space.
type Pathfinder ¶
type Pathfinder struct {
// contains filtered or unexported fields
}
Pathfinder is a simple A* pathfinding algorithm implementation.
func NewPathfinder ¶
func NewPathfinder(weights Grid[int], opts ...Option) Pathfinder
NewPathfinder creates a new Pathfinder with the given weights and options. The weights are used to determine the cost of traversing a cell. A weight of 0 means the cell is not traversable. A weight of 1 or higher means the cell is traversable.
func (Pathfinder) Find ¶
func (p Pathfinder) Find(startPos, endPos Vec2) []Vec2
Find returns a path from start to end. If no path is found, an empty slice is returned.