steps

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

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 steps runs the steps of rules and plans: the nodes packages cond, act and plan build, laid out as a tree, run at a moment within a pass (Instant) or every step on the entities' minds (Plans). Those packages are its face.

Index

Constants

View Source
const MaxCame = 8

MaxCame is how many facts one Until may wait for: a bit each in its slot.

Variables

View Source
var (
	// OfMe is the entity the rule or the plan is about.
	OfMe = Whose{/* contains filtered or unexported fields */}
	// OfSubject is the other of the pair the moment met, else the subject of the moment or
	// the fact; nobody while there is none.
	OfSubject = Whose{/* contains filtered or unexported fields */}
	// OfTarget is whom the steps act on now: the place the rule turned to.
	OfTarget = Whose{/* contains filtered or unexported fields */}
)

Functions

func PlanID

func PlanID(name string) uint64

PlanID is the id of the plan named name: the name hashed.

Types

type Aimed

type Aimed interface{ Aim(who uid.UID64) }

Aimed is a command told the subject of the fact or moment it stands under as it is issued.

type Guard

type Guard interface {
	// contains filtered or unexported methods
}

Guard is a condition a branch asks of somebody's state besides its fact or moment.

func GuardAll

func GuardAll(gs ...Guard) Guard

GuardAll holds while every guard does.

func GuardAlways

func GuardAlways(w Whose) Guard

GuardAlways holds while w is somebody.

func GuardAny

func GuardAny(gs ...Guard) Guard

GuardAny holds while any guard does.

func GuardCame

func GuardCame[F any](k uint8, w Whose) Guard

GuardCame holds once the fact F has come to the entity afresh since the loop began: one carried from before does not count. k is its bit in the Until's slot.

func GuardChance

func GuardChance(p float64, w Whose) Guard

GuardChance holds with the probability p, drawn afresh every step from the world's seed, the time and w, so a load and a replay draw alike.

func GuardNot

func GuardNot(g Guard) Guard

GuardNot holds while g does not.

func GuardPlaying

func GuardPlaying(bit uint8, w Whose) Guard

GuardPlaying holds while w plays the role of bit.

func GuardUnder

func GuardUnder(e effect.Effect, w Whose) Guard

GuardUnder holds while w is under e.

func GuardWord

func GuardWord[P any](name string, holds func(P) bool, w Whose) Guard

GuardWord holds while holds does of the moment P a rule stands on, or of the fact P the entity carries in a plan, w being somebody.

type Instant

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

Instant is a rule laid out for running at a moment, every step of it done within the pass.

func NewInstant

func NewInstant(name string, root Step, payload any) *Instant

NewInstant lays root out as the rule named name, run on the moment payload points to. It panics on a step that lasts over ticks or one the moment cannot run.

func (*Instant) Fire

func (r *Instant) Fire(p Pass, id uid.UID64, entity bool, subject uid.UID64, about bool)

Fire runs the rule once for id (entity false: for nobody), an Aimed command of it at subject when about.

type LowerAs

type LowerAs uint8

LowerAs is where a condition stands: at the top of a rule, where the roles it names narrow the host; inside a branch or a plan, where they are guards; or as a loop's Until, where a fact that comes is allowed.

const (
	AtTop LowerAs = iota
	Inside
	AsUntil
)

type Lowered

type Lowered interface {
	Lower(as LowerAs, name string) Lowering
}

Lowered is a condition laid down into a guard, by package cond.

type Lowering

type Lowering struct {
	Guard     Guard // nil for always
	SelfRoles []uint8
	OtherRole int         // -1 for none
	At        host.Places // the places the rule turns to, with Places over 0
	Places    int
	Words     []reflect.Type
	Came      int
}

Lowering is a condition as a branch takes it: its guard, the roles it asks at the top of a rule (bits of the roles' family), the places it turns to, the moments its words are of and how many facts it waits for (MaxCame at most).

type Pass

type Pass struct {
	Commands *command.Carrier
	Effects  effect.Runtime
	Dt       time.Duration
	Time     time.Duration // game time at the step's end
	Seed     uint64
	Places   func(moment any, p host.Places, each func(uid.UID64))
	Roles    func(id uid.UID64) uint64 // a bit a role
}

Pass is what a rule is told of the pass it fires in.

type Plans

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

Plans runs the plans of every entity with a Mind, once every step of the simulation, over the blocks of entities a store's binding hands it.

func NewPlans

func NewPlans(now func() time.Duration, seed uint64, fx effect.Runtime,
	commands *command.Carrier) *Plans

NewPlans is the plans on the clock now, drawing Chance from seed, casting fx and giving their commands to commands.

func (*Plans) Bind added in v0.2.0

func (s *Plans) Bind(facts store.Facts)

Bind lays every plan out and binds the facts their steps read and write to the store's columns. Call it once, as the binding sets up; a plan defined after panics.

func (*Plans) Define

func (c *Plans) Define(name string, root Step) uint64

Define lays root out as the plan named name and returns its id, what a Mind carries. A name defined twice, or after the plans are bound, panics.

func (*Plans) Facts added in v0.2.0

func (s *Plans) Facts() []reflect.Type

Facts are the types of the facts the plans read and write, for the store to keep.

func (*Plans) Roles

func (s *Plans) Roles(lookup func(uid.UID64) uint64)

Roles has the plans find the roles an entity plays with lookup.

func (*Plans) Tick added in v0.2.0

func (s *Plans) Tick(row store.Row, ids []uid.UID64, minds []store.Mind, dt time.Duration)

Tick runs the plans of one block of entities: ids and minds side by side, row what they carry, dt the step.

type Status

type Status uint8

Status is how a node stands after a tick.

const (
	// Running is a node not done yet: it goes on at the next tick.
	Running Status = iota
	// Success is a node done well.
	Success
	// Failure is a node that could not.
	Failure
)

type Step

type Step interface {
	// contains filtered or unexported methods
}

Step is a part of a rule or a plan, made by package rule.

func NewApply

func NewApply(e effect.Effect) Step

NewApply puts e on the entity, lasting as its Spec says.

func NewApplyFor

func NewApplyFor(e effect.Effect, d time.Duration) Step

NewApplyFor puts e on the entity for d.

func NewBranch

func NewBranch[P any](name string, guard Guard, node Step, until Guard) Step

NewBranch is a branch named name running node while guard holds, of the moment or the fact P. In a plan a branch of a fact runs once as the fact comes to hold, node to its end; one of any runs while its guard holds. With until, a plan's, the branch goes on after node is done and ends well once until holds, node halted.

func NewCooldown

func NewCooldown(d time.Duration, node Step) Step

func NewDispel

func NewDispel(e effect.Effect) Step

func NewFirst

func NewFirst(name string, nodes ...Step) Step

NewFirst is a OneOf named name.

func NewForOther

func NewForOther(step Step) Step

NewForOther runs step on each of the others the moment met, or on its subject, in place of the entity.

func NewIdle

func NewIdle() Step

func NewKeep

func NewKeep(e effect.Effect) Step

func NewOrder

func NewOrder[C command.Command](cmd C) Step

NewOrder gives the entity the command cmd, or sends it as a message where cmd carries a From.

func NewPlaces added in v0.2.1

func NewPlaces(at host.Places, step Step) Step

NewPlaces runs step on each of the places at the host tells for the moment, in place of the entity.

func NewSame

func NewSame(step Step) Step

NewSame runs step on the entity itself, inside a step acting on others.

func NewThen

func NewThen(name string, nodes ...Step) Step

NewThen is a Steps named name.

func NewTimeout

func NewTimeout(d time.Duration, node Step) Step

func NewWait

func NewWait(d time.Duration) Step

type Whose

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

Whose is whom a guard asks about.

func OfEntity

func OfEntity(of func() uid.UID64) Whose

OfEntity is the entity of gives, a plugin's own.

Jump to

Keyboard shortcuts

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