Expand description
Paths over a square grid: where a walker can go on a budget and the
cheapest path there (reachable), and how far every tile is from a
set of goals (flow_field). The game says what a tile costs with a
cost function; the rules of who may stand where stay the game’s.
§Rules
- Steps. Only the four grid directions (
Dir) are steps. A step pays the cost of the tile it enters: the cost function’s answer for that tile, or no step at all when it answersNone. The start costs nothing. The cost function is only asked about tiles inside the grid. - Budget.
reachablekeeps the tiles whose cheapest cost is at most the budget. - Determinism. Both searches are one Dijkstra. Its queue is ordered
by
(cost, y, x), neighbours are visited inDir::ALLorder, and a tile’s recorded predecessor only changes for a strictly cheaper cost. So among equally cheap paths to a tile, the one through the neighbour expanded first wins, every time. When every step costs at least 1, tiles are expanded in(cost, y, x)order, so that neighbour is the one with the smallest(cost, y, x)among those on a cheapest path. Steps that cost 0 can reach a tile at the cost being expanded but with a smaller(y, x)than tiles already expanded at that cost, so then the order is only cheapest first. - A cost that would pass
u32::MAXis no step.
Structs§
- Reach
- Where a walker can go from one tile on a budget, with the cheapest path
to each tile. Built by
reachable.
Functions§
- flow_
field - How far every tile of a
width × heightgrid is from the nearest ofgoals: the cost of the cheapest walk from the tile onto a goal, where entering a tile costscost(tile), as inreachable, and there is no budget. A goal is 0 from itself. A tile that can’t be entered has no distance (unless it is a goal), and neither has a tile with no walk to a goal: a goal that can’t be entered is never walked onto. Goals outside the grid are left out. - reachable
- Where a walker on
startcan go withbudgetto spend on awidth × heightgrid, where entering a tile costscost(tile)(None: it can’t be entered). A start outside the grid reaches nothing.