state

package
v0.0.0-...-e4f1321 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: GPL-2.0 Imports: 3 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	Units    int
	PlayerId PlayerId
	Reason   ChangeReason
}

type ChangeReason

type ChangeReason string

type Changes

type Changes []Change

type Edge

type Edge struct {
	// Src is the id of the source node.
	Src NodeId
	// Dst is the id of the destination node.
	Dst NodeId
	// Units contains the units in transit along the edge.
	Units []map[PlayerId]int
}

Edge goes from one node to another.

type GameId

type GameId string

type Node

type Node struct {
	// Id is the id of the node
	Id NodeId
	// Size is the number of units supported by the node. If less units, from a single player, occupy the node they will procreate. If more units occupy the node they will starve.
	Size int
	// Units contain the number of units for each player occupying this node.
	Units map[PlayerId]int
	// Edges go from this node to others.
	Edges map[NodeId]Edge
}

Nodes contain units, and are connected by edges.

func NewNode

func NewNode(id NodeId, size int) *Node

NewNode returns a node named id with size.

func RandomNode

func RandomNode() (result *Node)

RandomNode returns a random node without connections.

func (*Node) Connect

func (self *Node) Connect(node *Node, edgeLength int)

type NodeId

type NodeId string

type Order

type Order struct {
	// Src is from where the units should move.
	Src NodeId
	// Dst is where the units should move.
	Dst NodeId
	// Units is the number of units to move.
	Units int
}

Order contains a single order from an AI.

Orders will start units moving along edges of nodes, and they will be unorderable until they arrive.

type Orders

type Orders []Order

Orders are given by AIs to move around their units.

type PathFilter

type PathFilter func(node *Node) bool

PathFilter will return if a node is accepted by the filter.

type PlayerId

type PlayerId string

type State

type State struct {
	// Nodes are the nodes in the game.
	Nodes map[NodeId]*Node
	// Changes are the changes and reasons since last turn.
	Changes map[NodeId]Changes
	// Orders from each player
	Orders map[PlayerId]Orders
}

State completely describes a single turn of the game.

func NewState

func NewState() *State

func RandomState

func RandomState(c common.Logger, players []PlayerId) (result *State)

RandomState creates a random state for the provided players.

func (*State) Add

func (self *State) Add(n *Node) *State

func (*State) Clone

func (self *State) Clone() (result *State)

func (*State) Next

func (self *State) Next(c common.Logger, orderMap map[PlayerId]Orders) (winner *PlayerId)

Next changes this state into the next state, subject to the provided orders.

func (*State) Path

func (self *State) Path(src, dst NodeId, filter PathFilter) (result []NodeId)

Path will return the shortest path between src and dst in self, discounting all paths that don't match the filter. A nil filter matches all nodes.

Jump to

Keyboard shortcuts

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