network

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 5 Imported by: 1 module, 1 package

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 network is what runs from cell to cell across a board, rivers and roads, as a graph over its grid: the cells it runs through (Network.Set, a Node of a board kind, a width and a fade) and which neighbours each runs on to; a road [Network.Link]s its cells both ways, water [Network.Flow]s down to where it leaves the network. It is a way to make a board's layout, not a plugin: a game works one out, by hand or as plugins/board/water drains a relief, and lays it on the board as its Network.Ways; Network.Along is how far down its flow a cell lies, Network.Crossings where two networks meet. A road is found over the grid with Route and laid along its cells with Network.Path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Route

func Route(grid grid.Grid, from, to cell.ID, cost func(a, b cell.ID) float64) ([]cell.ID, bool)

Route is the cheapest way over grid from one cell to another, stepping from a cell to a neighbour at what cost says — +Inf where the step may not be taken: the cells in order, from and to included; false where no way gets there.

Types

type Network

type Network struct {
	// contains filtered or unexported fields
}

Network is what runs from cell to cell over a board's grid — a river, a road: the cells it runs through and which of their neighbours each runs on to. A link that Flows has a way down: water running from cell to cell towards where it leaves the network, the sea.

func New

func New(grid grid.Grid) *Network

New is an empty network over grid.

func (*Network) Along

func (n *Network) Along(c cell.ID) float64

Along is how far down its flow c lies: 0 at the head of the longest flow running into it, 1 at the last cell before it leaves the network, by the cells above and below it; 0 where the network does not run, or does not flow.

func (*Network) Cells

func (n *Network) Cells() []cell.ID

Cells is every cell the network runs through, in order.

func (*Network) Crossings

func (n *Network) Crossings(o *Network) []cell.ID

Crossings is every cell both n and o run through: where a road meets a river, a ford or a bridge.

func (*Network) Down

func (n *Network) Down(c cell.ID) (cell.ID, bool)

Down is where c runs down on to, Flow's; false where it flows nowhere.

func (*Network) Flow

func (n *Network) Flow(from, to cell.ID) bool

Flow has from run down on to its neighbour to, linked back where the network runs through to; a river's last cell runs on to the sea, which is no part of it. It is false where they are no neighbours.

func (*Network) Lead added in v0.22.0

func (n *Network) Lead(a, b cell.ID) bool

Lead has a run on to its neighbour b and b not back: a way led onto what stands in b's cell, a bridge, a ford or a tunnel, leaves a way running in that cell as it was; false where they are no neighbours.

func (n *Network) Link(a, b cell.ID) bool

Link has a and b, neighbours, run on to each other; false where they are no neighbours.

func (n *Network) Links(c cell.ID) cell.Links

Links is which of c's neighbours the network runs on to from it; none where it does not run.

func (*Network) Node

func (n *Network) Node(c cell.ID) (Node, bool)

Node is what runs through c; false where nothing does.

func (*Network) Path

func (n *Network) Path(cells []cell.ID, node Node)

Path has the network run along cells, each a node as given, each linked to the next.

func (*Network) Set

func (n *Network) Set(c cell.ID, node Node)

Set has the network run through c as node says.

func (*Network) Ways

func (n *Network) Ways() []cell.WayEntry

Ways is the network laid on a board: a Way across every cell it runs through, of its node's kind, as wide and faded, running on as Links says, its look turned as far down its flow as it lies.

type Node

type Node struct {
	Kind  string
	Width float32
	Fade  float32
}

Node is a cell a network runs through: the board kind its way is laid of, named, how wide it runs in world units, and how far it has faded out, 0 not at all to 1 gone.

Jump to

Keyboard shortcuts

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