tilemap

package
v0.0.0-...-f130474 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToInts

func ToInts(v rune) int

func ToRunes

func ToRunes(v rune) rune

Types

type Container

type Container[T any] 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 (t Container[T]) PathEstimatedCost(to astar.Pather) float64

func (Container[T]) PathNeighborCost

func (t Container[T]) PathNeighborCost(to astar.Pather) float64

func (Container[T]) PathNeighbors

func (t Container[T]) PathNeighbors() (results []astar.Pather)

type Map

type Map[T any] 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

func FromInput(input *challenge.Input) *Map[rune]

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 any](input *challenge.Input, 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 any](w, h int) *Map[T]

Of creates a new empty tile map of the specified type and size

func (*Map[T]) ContainerAt

func (t *Map[T]) ContainerAt(x, y int) (Container[T], bool)

ContainerAt returns the tile container at the specified coordinates in the tile map

func (*Map[T]) PathBetween

func (t *Map[T]) PathBetween(startX, startY, endX, endY int) ([]astar.Pather, float64, bool)

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

func (*Map[T]) SetTile

func (t *Map[T]) SetTile(x, y int, tile T)

SetTile stores the specified tile at location (x,y) in the tile map

func (*Map[T]) Size

func (t *Map[T]) Size() (int, int)

Size returns the width and height of the tile map

func (*Map[T]) TileAt

func (t *Map[T]) TileAt(x, y int) (T, bool)

TileAt returns the value of the Tile at the specified coordinates in the map

Jump to

Keyboard shortcuts

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