astar

package module
v0.0.0-...-ab82bd1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2019 License: MIT Imports: 2 Imported by: 0

README

go-astar

Build Status

This is a modified version of Michael Alexander's go-astar that uses fixed point math.

Authors

Michael Alexander beefsack@gmail.com Robin Ranjit Chauhan robin@pathwayi.com Andreas T Jonsson mail@andreasjonsson.se

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	PathNeighbors(node Pather, buf []Pather) []Pather
	PathNeighborCost(node Pather, to Pather) fix16.T
}

Optional user context.

type Goreland

type Goreland struct {
}

func (Goreland) RenderPath

func (w Goreland) RenderPath(path []Pather) string

RenderPath renders a path on top of a Goreland world.

type Pather

type Pather interface {
	// PathNeighbors returns the direct neighboring nodes of this node which
	// can be pathed to.
	PathNeighbors(ctx Context, buf []Pather) []Pather
	// PathNeighbourCost calculates the exact movement cost to neighbor nodes.
	PathNeighborCost(ctx Context, to Pather) fix16.T
	// PathEstimatedCost is a heuristic method for estimating movement costs
	// between non-adjacent nodes.
	PathEstimatedCost(ctx Context, to Pather) fix16.T
}

Pather is an interface which allows A* searching on arbitrary objects which can represent a weighted graph.

func Path

func Path(from, to Pather) (path []Pather, distance fix16.T, found bool)

Path calculates a short path and the distance between the two Pather nodes.

func PathWithContext

func PathWithContext(ctx Context, from, to Pather) (path []Pather, distance fix16.T, found bool)

PathWithContext calculates a short path and the distance between the two Pather nodes. ctx is user optional data. If no path is found, found will be false.

type Search struct {
	// contains filtered or unexported fields
}

Search is an object representing the current search state.

func NewSearch

func NewSearch(ctx Context, from, to Pather) *Search

NewSearch creates a new search object.

func (*Search) Context

func (s *Search) Context() Context

Context returns the users search context.

func (*Search) Result

func (s *Search) Result() (path []Pather, distance fix16.T, found bool)

Result retrives the final search result.

func (*Search) Step

func (s *Search) Step() bool

Step advances the search.

Returns true if the search is done.

type Truck

type Truck struct {

	// X and Y are the coordinates of the truck.
	X, Y int
	// contains filtered or unexported fields
}

A Truck is a Truck in a grid which implements Grapher.

func (*Truck) PathEstimatedCost

func (t *Truck) PathEstimatedCost(_ Context, to Pather) fix16.T

PathEstimatedCost uses Manhattan distance to estimate orthogonal distance between non-adjacent nodes.

func (*Truck) PathNeighborCost

func (t *Truck) PathNeighborCost(_ Context, to Pather) fix16.T

PathNeighborCost returns the cost of the tube leading to Truck.

func (*Truck) PathNeighbors

func (t *Truck) PathNeighbors(_ Context, neighbors []Pather) []Pather

PathNeighbors returns the neighbors of the Truck

type Tube

type Tube struct {
	Cost fix16.T
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL