testmap

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testmap is the maps the tests and the benchmarks of package hpastar search: square maps generated from a seed, rough ground and walls in short lines, a torus or not, walked eight ways, as hexagons or with a second state over a stretch, their steps refused to classes and each class's graph alone, and the small grids of costs the A* engine's paths are pinned on.

Index

Constants

View Source
const InsurmountableObstacle = 100.0

InsurmountableObstacle is the cost of a wall of a grid, a cell no step enters.

Variables

This section is empty.

Functions

func Dicts

func Dicts(size int) map[string]func() dict.Dict[Point]

Dicts are the dictionaries an engine over a grid of size × size may keep its nodes in, by name, each made anew.

func EightWays

func EightWays(grid [][]float64) graph.Transitions[Point]

EightWays walks grid eight ways: a wall is never entered, a step costs the cell entered, a slantwise one √2 of it.

func Filtered added in v1.4.0

func Filtered[T comparable](g graph.Implicit[T], k int) graph.Implicit[T]

Filtered is g as its class k steps it, a graph of one class: the steps k refuses left out, the others refused to none.

func FourWays

func FourWays(costWeight float64, grid [][]float64) graph.Transitions[Point]

FourWays walks grid four ways, a step costing the cell entered times costWeight; a step of 100 or more is not taken.

func Hashed added in v1.4.0

func Hashed(seed uint64, from, to int) float64

Hashed is a number in [0, 1) of the step from from into to, drawn from seed, another for the step back.

func Identity

func Identity(s int) int

Identity is a cell's index, the cell itself.

func Manhattan

func Manhattan(p, g Point) float64

Manhattan is the Manhattan distance.

func Masked added in v1.4.0

func Masked[T comparable](g graph.Implicit[T], classes int,
	refuse func(from, to T) uint8) graph.Implicit[T]

Masked is g serving classes classes, a step from from into to refused to the classes whose bits refuse(from, to) has, Forward and Backward alike.

func Octile

func Octile(p, g Point) float64

Octile is the octile distance, which never overestimates on a grid where no step costs less than its length.

func PathCost

func PathCost(grid [][]float64, path []Point) float64

PathCost is the cost of path over grid as FourWays and EightWays price it: the cell entered, a slantwise step √2 of it.

func Queries

func Queries(grid [][]float64, seed uint64) [][2]Point

Queries are the corners of grid both ways, a cell to itself, the first wall if any, then forty pairs of open cells drawn from seed.

func RandomGrid

func RandomGrid(size int, seed uint64) [][]float64

RandomGrid is a grid of costs of 1 to 5 and a wall on a fifth of the cells, the corners kept open.

func SkipLarge

func SkipLarge(tb testing.TB, size int)

SkipLarge skips tb on a map of 4096x4096 or more unless HPASTAR_SCALE=4096 asks for one: a hierarchy over it takes a minute and most of a gigabyte to build.

func Splitmix

func Splitmix(seed uint64) func() float64

Splitmix is a deterministic source of numbers in [0, 1) for the maps.

func UniformGrid

func UniformGrid(size int) [][]float64

UniformGrid is a grid of cells of cost 1.

func WalkCost

func WalkCost(steps graph.Transitions[int], route []int) (float64, bool)

WalkCost is what route costs stepped along steps; false where a step is not a transition.

func WalledGrid

func WalledGrid(size int) [][]float64

WalledGrid is a grid of costs 1 to 5 by the cells' diagonals, walled on most of every fourth column, its corners open.

Types

type Map

type Map struct {
	W, H  int
	Share []float32
	Wrap  bool
}

Map is a square map of cells for the tests and the benchmarks: each cell's share of full pace (0 a wall), reproducible from a seed; Wrap makes it a torus.

func New

func New(seed uint64, size int, walls float64, wrap bool) *Map

New is a map of size × size cells: ground from smooth value noise with shares between 0.13 and 1 (as rough ground to a road), walls on the share of cells walls says, laid as short lines so that pockets and detours form.

func (*Map) AnyOpen

func (m *Map) AnyOpen(rnd func() float64) int

AnyOpen is an open cell drawn from rnd.

func (*Map) Apart

func (m *Map) Apart(rnd func() float64, from, n int, near, far float64) []int

Apart draws n open cells from rnd, each at least near from from by the octile distance and, where far is above 0, at most far.

func (*Map) At

func (m *Map) At(x, y int) (int, bool)

At is the cell at x, y, across the seams of a torus; false off a map with edges.

func (*Map) Backward

func (m *Map) Backward(to, _ int, buf []graph.Transition[int]) []graph.Transition[int]

Backward is Forward seen from the destination: the states a step leads from into to, each at the cost of that step.

func (*Map) Barred added in v1.4.0

func (m *Map) Barred(classes int, bars []uint8) graph.Implicit[int]

Barred is the map's graph serving classes classes, a step into a state refused to the classes bars has for it.

func (*Map) Bars added in v1.4.0

func (m *Map) Bars(seed uint64, classes int, share float64, within func(x, y int) bool) []uint8

Bars draws from seed, for each state of the map with chance share, the classes barred from stepping into it: every class from one drawn up, so that class 0 is never barred and a class is barred wherever one below it is. Within, where not nil, keeps the bars to its places.

func (*Map) Coords

func (m *Map) Coords(c int) (x, y int, ok bool)

Coords is where cell c lies; false for no cell of the map.

func (*Map) FarPair

func (m *Map) FarPair() [2]int

FarPair is two open cells near opposite corners, an eighth of the side in from each: a route across most of a map with edges.

func (*Map) Forward

func (m *Map) Forward(from, _ int, buf []graph.Transition[int]) []graph.Transition[int]

Forward is the map's transitions: eight directions, a step priced by its length over the share of the cell it enters, none into a wall.

func (*Map) Gated

func (m *Map) Gated(at int) (graph.Implicit[int], int)

Gated is the map's graph with a gate past its cells, a state off the plane stepping only to at, and the gate.

func (*Map) Graph

func (m *Map) Graph() graph.Implicit[int]

Graph is the map's graph laid out in the plane, a state y·W + x.

func (*Map) Hex added in v1.4.0

func (m *Map) Hex() graph.Implicit[int]

Hex is the map's graph walked as a parallelogram of axial hexagons: six neighbours a state, a step priced as the map prices its own, the hex distance its estimate.

func (*Map) Layered added in v1.4.0

func (m *Map) Layered(y, x0, x1 int) graph.Implicit[int]

Layered is the map's graph with a second state at each place of row y from x0 to x1, keyed past the map's own: those step along the row both ways at cost 1, and at its ends onto the map's states next to them and back.

func (*Map) Octile

func (m *Map) Octile(a, b int) float64

Octile is the octile distance, which never overestimates: no step costs less than its length.

func (*Map) OpenNear

func (m *Map) OpenNear(x, y int) int

OpenNear is the open cell nearest x, y, looked for a ring of cells at a time; -1 where the map has none.

func (*Map) Pairs

func (m *Map) Pairs(seed uint64, n int, lo, hi float64) [][2]int

Pairs are n pairs of open cells drawn from seed, lo to hi apart by the octile distance.

func (*Map) States

func (m *Map) States(x, y int, buf []int) []int

States appends the cell at x, y to buf, none for a wall.

func (*Map) WallRing

func (m *Map) WallRing(x0, y0, side int)

WallRing walls off the square of side cells at x0, y0 with a ring a cell thick, which no step crosses, slantwise either: its inside reaches nothing outside.

type Point

type Point struct {
	X, Y int
}

Point is a cell of a grid of costs.

Jump to

Keyboard shortcuts

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