pathing

package
v0.0.1 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

Overview

Package pathing builds shared flow fields over a grid.Grid.

Rebuild once when walkability changes (build-phase end, tower place/sell). Units sample Direction or Next each tick instead of running A* per agent.

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, exit Cell) bool

SpawnsCanReachExit reports whether every spawn can reach the exit. Empty spawn 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
	ExitX  int
	ExitY  int
	// contains filtered or unexported fields
}

Field is a reverse-BFS flow field toward one exit cell.

For each reachable walkable tile, Next points one step closer to the exit. The exit cell points at itself. Unreachable cells have no next step.

func Rebuild

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

Rebuild computes a flow field from every walkable cell toward (exitX, exitY).

Cost is O(width*height). Call when the map becomes dirty — not every frame.

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 the 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 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 the exit. ok is false when (x, y) is out of bounds or unreachable. At the 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 the exit.

Jump to

Keyboard shortcuts

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