plan

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 11 Imported by: ? 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 plan is what an entity does over time: loops run on its mind every step, made of the same steps a rule has and of what lasts.

plan.New("order", plan.OneOf(
	plan.Loop[Received]{
		Name:    "fulfil",
		When:    cond.Self.If(cond.Always),
		Then:    plan.Self.Do(Invoice{}),
		Until:   cond.Self.If(Paid{}),
		Timeout: 14 * 24 * time.Hour,
	},
	plan.Loop[any]{Name: "idle", When: cond.Self.If(cond.Always), Then: plan.Self.Idle()},
))

Loops

A Loop says when it begins (When), what it does (Then) and when it ends: Until, a condition that comes to hold from its start — a fact's value in it, cond.Self.If(reply{}), is the fact come afresh — Timeout, after which it fails, and Cooldown, within which it does not begin again. A plan done begins again the next step. Steps runs loops in turn, OneOf the first whose When holds, an earlier one taking over once it can.

Steps

Self has every step a rule's act.Self has, and Entity.Wait and Entity.Idle, which last; Other is act.Other. A rule's steps and groups (act.Self.Do, act.Steps) are parts of a plan too; a plan's are not a rule's.

Plans

New makes a Planned, the plan's mind as a kind's component; Plans runs every plan registered on it (Plans.Register) over the entities a store's binding hands it (Plans.Bind, Plans.Tick) on the clock and the seed it was made with (NewPlans).

Index

Constants

This section is empty.

Variables

View Source
var (
	// Self is the entity the plan is about.
	Self = Entity{act.Self}
	// Other is the subject of the fact the loop stands on; a step of it fails while there is
	// none.
	Other = act.Other
)
View Source
var Around = act.Around

Around is a rule's; a plan has no places.

Functions

This section is empty.

Types

type Entity

type Entity struct{ act.Subject }

Entity is the entity the plan is about, with the steps that last besides a rule's.

func (Entity) Idle

func (Entity) Idle() Part

Idle is the entity doing nothing for ever: a loop that only waits for its Until, or the last part of a OneOf.

func (Entity) Wait

func (Entity) Wait(d time.Duration) Part

Wait is the entity doing nothing for d, then done well.

type Loop

type Loop[P any] struct {
	Name     string        // required at the top of a plan
	When     cond.Cond     // required: cond.Self.If(cond.Always) for every time
	Then     Part          // required
	Until    cond.Cond     // ends well once it holds; a fact in it is one come afresh
	Timeout  time.Duration // fails once it has run this long
	Cooldown time.Duration // does not begin again within this of its last run
}

Loop is what an entity does over time on the fact P (any for none): Then run from the start as When comes to hold, going on until Until holds, failing after Timeout, not beginning again within Cooldown of its last run. A loop of a fact begins once as the fact comes to hold its When and runs to the end; one of any runs while its When holds.

func (Loop[P]) Lasting

func (l Loop[P]) Lasting() act.Lasting

Lasting is the loop as the plan is built (Part).

type Part

type Part interface {
	// Lasting is the part as the plan is built.
	Lasting() act.Lasting
}

Part is a part of a plan: a rule's step (act.Step), a step that lasts (Self.Wait, Self.Idle), a Loop, or Steps and OneOf of them.

func OneOf

func OneOf(parts ...Part) Part

OneOf does as the first of its parts that does not fail: every tick from the top, an earlier part taking over from a later one once it can.

func Steps

func Steps(parts ...Part) Part

Steps runs its parts one after another while each does well, remembering where it is, and fails with the first that fails.

type Planned added in v0.2.0

type Planned struct {
	comp.Template[store.Mind]
	// contains filtered or unexported fields
}

Planned is what New makes: the plan's mind as a kind's component, registered on the Plans of the world the kind is defined in.

func New

func New(name string, root Part) Planned

New is the plan named name: root run in every step of the simulation, given to a kind in its Spec; a loop at its top says its Name. A name defined twice in one world panics.

func (Planned) Name added in v0.2.0

func (p Planned) Name() string

Name is the plan's.

type Plans

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

Plans runs the plans of every entity with a store.Mind, once every step of the simulation: a store's binding binds it and ticks it over the blocks of entities it walks.

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 (ps *Plans) Bind(facts store.Facts)

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

func (*Plans) Facts added in v0.2.0

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

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

func (*Plans) Register added in v0.2.0

func (ps *Plans) Register(p Planned)

Register defines p on the plans, once; a name defined twice, or after Bind, panics.

func (*Plans) Roles added in v0.2.0

func (ps *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 (ps *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.

Jump to

Keyboard shortcuts

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