Documentation
¶
Index ¶
- func ToInts(v rune) int
- func ToRunes(v rune) rune
- type Container
- type Map
- func (t *Map[T]) AllContainersWith(v T) (results []Container[T])
- func (t *Map[T]) AllNeighbors(x, y int) iter.Seq2[T, Point]
- func (t *Map[T]) CardinalNeighbors(x, y int) iter.Seq2[T, Point]
- func (t *Map[T]) ContainerAt(x, y int) (Container[T], bool)
- func (t *Map[T]) FirstContainerWith(v T) (Container[T], bool)
- func (t *Map[T]) PathBetween(startX, startY, endX, endY int) ([]astar.Pather, float64, bool)
- func (t *Map[T]) SetTile(x, y int, tile T)
- func (t *Map[T]) Size() (int, int)
- func (t *Map[T]) TileAt(x, y int) (T, bool)
- func (t *Map[T]) Values() iter.Seq2[T, Point]
- type Point
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Container ¶
type Container[T comparable] struct { Value T // contains filtered or unexported fields }
Container represents the intermediate object stored in the tile map. This container type implements astar.Pather with the following assumptions:
* Neighbors on the cardinal direction are reachable if they exist in the tile map * The cost to traverse any neighbor is always 1 * The cost estimate between any two points in the map is the manhattan distance between them
To override these, override Map.NeighborFunc, Map.CostFunc, and Map.EstimateFunc
func (Container[T]) PathEstimatedCost ¶
func (Container[T]) PathNeighborCost ¶
func (Container[T]) PathNeighbors ¶
func (t Container[T]) PathNeighbors() (results []astar.Pather)
type Map ¶
type Map[T comparable] struct { NeighborFunc func(container Container[T]) []Container[T] CostFunc func(a, b Container[T]) float64 EstimateFunc func(a, b Container[T]) float64 // contains filtered or unexported fields }
Map represents a fixed size grid of tiles. The top-left tile is [0,0], the bottom-right tile is [w, h]. Tiles are stored internally in a Container which implements astar.Pather with the following assumptions:
* Neighbors on the cardinal direction are reachable if they exist in the tile map * The cost to traverse any neighbor is always 1 * The cost estimate between any two points in the map is the manhattan distance between them
To override these, override Map.NeighborFunc, Map.CostFunc, and Map.EstimateFunc
func FromInput ¶
FromInput creates a Map of runes from the input where each line is one row in the map and each rune in each line is a column.
func FromInputOf ¶
func FromInputOf[T comparable](input io.Reader, convert func(rune) T) *Map[T]
FromInputOf creates a Map of the specified type from the input where each line is one row in the map and each rune in each line is a column whose value is computed using the provided conversion function.
func Of ¶
func Of[T comparable](w, h int) *Map[T]
Of creates a new empty tile map of the specified type and size
func (*Map[T]) AllContainersWith ¶
func (*Map[T]) AllNeighbors ¶
AllNeighbors returns an iter.Seq2 over the 8 surrounding tiles of the specified tile, if they also exist in the map.
It is OK to change the value of tiles while iterating the returned sequence, but tiles should not be added to or removed from the map while iterating.
func (*Map[T]) CardinalNeighbors ¶
CardinalNeighbors returns an iter.Seq2 over neighbors directly North, South, East, or West of the specified location in the map, if they also exist in the map.
It is OK to change the value of tiles while iterating the returned sequence, but tiles should not be added to or removed from the map while iterating.
func (*Map[T]) ContainerAt ¶
ContainerAt returns the tile container at the specified coordinates in the tile map
func (*Map[T]) FirstContainerWith ¶
func (*Map[T]) PathBetween ¶
PathBetween uses the A-Star path finding algorithm to find the most efficient path between the two locations in the map. By default, the following constraints are used for finding the path:
* Neighbors on the cardinal direction are reachable if they exist in the tile map * The cost to traverse any neighbor is always 1 * The cost estimate between any two points in the map is the manhattan distance between them
To override these, override Map.NeighborFunc, Map.CostFunc, and Map.EstimateFunc