astar

package
v0.0.0-...-e72e60e Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2014 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AStar

type AStar interface {
	// Fill a given tile with a given weight this is used for making certain areas more complicated
	// to cross than others. For example you may have a higher weight for a wall or mountain.
	// This weight will be given back to you in the SetWeight function
	// Inbuilt A*'s use -1 to determine that it can not be passed at all.
	FillTile(p Point, weight int)

	// Resets the weight back to 0 for a given tile
	ClearTile(p Point)

	// Calculate the easiest path from ANY element in source to ANY element in target.
	// There is no hard rules about which element will become the start and end (unless your config
	// enforces it).
	// The start of the path is returned to you. If no path exists then the function will
	// return nil as the path.
	FindPath(config AStarConfig, source, target []Point) *PathPoint
}

func NewAStar

func NewAStar(rows, cols int) AStar

type AStarConfig

type AStarConfig interface {
	// Determine if a valid end point has been reached. The end parameter
	// is the value passed in as source because the algorithm works backwards.
	IsEnd(p Point, end []Point, end_map map[Point]bool) bool

	// Calculate and set the weight for p.
	// fill_weight is the weight assigned to the tile when FillTile was called
	// or 0 if it was never called for that tile.
	// end is also provided so you can perform calculations such as distance remaining.
	SetWeight(p *PathPoint, fill_weight int, end []Point, end_map map[Point]bool) (allowed bool)

	// PostProcess the path after it has been calculated this might be useful if you want do do things
	// like reverse it or add constant moves at the start or end etc.
	PostProcess(p *PathPoint, rows, cols int, filledTiles map[Point]int) *PathPoint
}

The user built configuration that determines how weights are calculated and also determines the stopping condition

func NewListToPoint

func NewListToPoint(reverse bool) AStarConfig

list to point routing, from a list of points to a single point. multiple targets are supported but is slower than the others.

Weights are calulated by summing the tiles fill_weight, the total distance traveled and the current distance from the closeset target

The reverse parameter determines if the final path is returned in reverse. This uses the ReversePostProcessing struct and can be useful if you want to for example find a route back to the main path, instead of from the path to a particular place.

func NewPointToPoint

func NewPointToPoint() AStarConfig

Basic point to point routing, only a single source is supported and it will panic if given multiple sources

Weights are calulated by summing the tiles fill_weight, the total distance traveled and the current distance from the target

func NewRowToRow

func NewRowToRow() AStarConfig

Based off the PointToPoint config except that it uses row based targeting. The column value is ignored when calculating the weight and when determining if we have reached the end.

A single point should be given for the source which will determine the starting row. for the target you should provide every valid entry on the target row for the best results. you do not have to but the path may look a little strange sometimes.

type PathPoint

type PathPoint struct {
	Point
	Parent *PathPoint

	Weight       int
	FillWeight   int
	DistTraveled int

	WeightData interface{}
}

A point along a path. FillWeight is the sum of all the fill weights so far and DistTraveled is the total distance traveled so far

WeightData is an interface that can be set to anything that Config wants it will never be touched by the rest of the code but if you wish to have any custom data held per node you can use WeightData

type Point

type Point struct {
	Row int
	Col int
}

func (Point) Dist

func (p Point) Dist(other Point) int

Manhattan distance NOT euclidean distance because in our routing we cant go diagonally between the points.

type ReversePostProcess

type ReversePostProcess struct {
}

A post processing struct that will reverse the path thats given to it listToPoint for example can only generate from path to target target not the other way around so you can use this struct to apply reversing to the final path

func (*ReversePostProcess) PostProcess

func (v *ReversePostProcess) PostProcess(p *PathPoint, rows, cols int, filledTiles map[Point]int) *PathPoint

type VoidPostProcess

type VoidPostProcess struct {
}

A post processing struct that can be embedded into a config and have no postprocessing applied

func (*VoidPostProcess) PostProcess

func (v *VoidPostProcess) PostProcess(p *PathPoint, rows, cols int, filledTiles map[Point]int) *PathPoint

Jump to

Keyboard shortcuts

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