pathing

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllReachable

func AllReachable(f *Field, cells []Cell) bool

AllReachable reports whether every cell in cells is reachable on an already-built flow field.

func CanReach

func CanReach(g *grid.Grid, sx, sy, tx, ty int) bool

CanReach reports whether a walkable path exists from (sx,sy) to (tx,ty) on the current grid (4-connected). Does not build a full flow field.

func SpawnsCanReachExit

func SpawnsCanReachExit(g *grid.Grid, spawns []Cell, exits []Cell) bool

SpawnsCanReachExit reports whether every spawn can reach at least one exit. Empty spawn or exit lists return false.

Types

type Cell

type Cell struct {
	X, Y int
}

Cell is a grid coordinate used for spawn/exit lists.

type Field

type Field struct {
	Width  int
	Height int
	Exits  []Cell
	// contains filtered or unexported fields
}

Field is a reverse-BFS flow field toward one or more exit cells.

For each reachable walkable tile, Next points one step closer to an exit. Exit cells point at themselves. Unreachable cells have no next step.

When several downhill neighbors share the same Dist, Next prefers moving down (increasing Y) before sideways — so creeps drop straight toward a bottom exit strip when the maze opens up.

func Rebuild

func Rebuild(g *grid.Grid, exitX, exitY int) (*Field, error)

Rebuild computes a flow field toward a single exit cell.

func RebuildFromExits added in v0.0.2

func RebuildFromExits(g *grid.Grid, exits []Cell) (*Field, error)

RebuildFromExits computes a flow field toward any of the given exit cells (multi-source reverse BFS). Cost is O(width*height).

func (*Field) Direction

func (f *Field) Direction(x, y int) (dx, dy float64, ok bool)

Direction returns a unit vector from cell (x, y) toward its next step. At an exit, or when unreachable, ok is false and dx, dy are 0.

func (*Field) Dist

func (f *Field) Dist(x, y int) int

Dist returns steps from (x, y) to the nearest exit, or -1 if unreachable.

func (*Field) Next

func (f *Field) Next(x, y int) (nx, ny int, ok bool)

Next returns the neighboring cell one step closer to an exit. ok is false when (x, y) is out of bounds or unreachable. At an exit, Next returns the exit itself.

func (*Field) Reachable

func (f *Field) Reachable(x, y int) bool

Reachable reports whether (x, y) has a path to an exit.

Jump to

Keyboard shortcuts

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