behaviortree

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package behaviortree provides a hierarchical behavior tree implementation for WoW bot AI. All node types implement the Node interface. Composite nodes (Selector, Sequence, Parallel) manage children; Decorator wraps a single child; Action and Condition are leaves. The tree is ticked once per update cycle by calling Tick on the root.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

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

Action is a leaf node that executes a function.

func NewAction

func NewAction(name string, fn func(bb *Blackboard) Status) *Action

func (*Action) Name

func (a *Action) Name() string

func (*Action) Reset

func (a *Action) Reset()

func (*Action) Tick

func (a *Action) Tick(bb *Blackboard) Status

type Blackboard

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

Blackboard is shared state accessible to all nodes in a tree.

func NewBlackboard

func NewBlackboard() *Blackboard

NewBlackboard creates a new empty blackboard.

func (*Blackboard) Delete

func (b *Blackboard) Delete(key string)

Delete removes a value.

func (*Blackboard) Get

func (b *Blackboard) Get(key string) (interface{}, bool)

Get retrieves a value.

func (*Blackboard) GetBool

func (b *Blackboard) GetBool(key string) bool

GetBool returns a bool value or false if not found.

func (*Blackboard) GetFloat

func (b *Blackboard) GetFloat(key string) float64

GetFloat returns a float64 value or 0 if not found.

func (*Blackboard) GetInt

func (b *Blackboard) GetInt(key string) int

GetInt returns an int value or 0 if not found.

func (*Blackboard) GetString

func (b *Blackboard) GetString(key string) string

GetString returns a string value or empty if not found.

func (*Blackboard) Set

func (b *Blackboard) Set(key string, val interface{})

Set stores a value.

type Condition

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

Condition is a leaf node that checks a condition and returns Success or Failure.

func NewCondition

func NewCondition(name string, fn func(bb *Blackboard) bool) *Condition

func (*Condition) Name

func (c *Condition) Name() string

func (*Condition) Reset

func (c *Condition) Reset()

func (*Condition) Tick

func (c *Condition) Tick(bb *Blackboard) Status

type DynamicNode

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

DynamicNode is a node whose behavior can be swapped at runtime. This is used for Lua-driven behavior replacement.

func NewDynamicNode

func NewDynamicNode(name string, initial Node) *DynamicNode

func (*DynamicNode) Name

func (d *DynamicNode) Name() string

func (*DynamicNode) Reset

func (d *DynamicNode) Reset()

func (*DynamicNode) SetNode

func (d *DynamicNode) SetNode(n Node)

SetNode replaces the underlying node at runtime.

func (*DynamicNode) Tick

func (d *DynamicNode) Tick(bb *Blackboard) Status

type Inverter

type Inverter struct {
	Child Node
	// contains filtered or unexported fields
}

Inverter inverts the result of its child: Success->Failure, Failure->Success.

func NewInverter

func NewInverter(name string, child Node) *Inverter

func (*Inverter) Name

func (i *Inverter) Name() string

func (*Inverter) Reset

func (i *Inverter) Reset()

func (*Inverter) Tick

func (i *Inverter) Tick(bb *Blackboard) Status

type Node

type Node interface {
	Tick(bb *Blackboard) Status
	Reset()
	Name() string
}

Node is the interface for all behavior tree nodes.

type Parallel

type Parallel struct {
	Children []Node
	// contains filtered or unexported fields
}

Parallel runs all children every tick. Succeeds when successThreshold children have succeeded, fails when failThreshold children have failed.

func NewParallel

func NewParallel(name string, successThreshold, failThreshold int, children ...Node) *Parallel

func (*Parallel) Name

func (p *Parallel) Name() string

func (*Parallel) Reset

func (p *Parallel) Reset()

func (*Parallel) Tick

func (p *Parallel) Tick(bb *Blackboard) Status

type Repeater

type Repeater struct {
	Child Node
	// contains filtered or unexported fields
}

Repeater ticks its child n times (0 means infinite until failure).

func NewRepeater

func NewRepeater(name string, limit int, child Node) *Repeater

func (*Repeater) Name

func (r *Repeater) Name() string

func (*Repeater) Reset

func (r *Repeater) Reset()

func (*Repeater) Tick

func (r *Repeater) Tick(bb *Blackboard) Status

type Selector

type Selector struct {
	Children []Node
	// contains filtered or unexported fields
}

Selector tries children left-to-right and succeeds as soon as one succeeds. If a child returns Running, the selector also returns Running.

func NewSelector

func NewSelector(name string, children ...Node) *Selector

func (*Selector) Name

func (s *Selector) Name() string

func (*Selector) Reset

func (s *Selector) Reset()

func (*Selector) Tick

func (s *Selector) Tick(bb *Blackboard) Status

type Sequence

type Sequence struct {
	Children []Node
	// contains filtered or unexported fields
}

Sequence runs children left-to-right and fails as soon as one fails.

func NewSequence

func NewSequence(name string, children ...Node) *Sequence

func (*Sequence) Name

func (s *Sequence) Name() string

func (*Sequence) Reset

func (s *Sequence) Reset()

func (*Sequence) Tick

func (s *Sequence) Tick(bb *Blackboard) Status

type Status

type Status int

Status is the result returned by a node tick.

const (
	// Success means the node completed successfully.
	Success Status = iota
	// Failure means the node failed.
	Failure
	// Running means the node is still executing and will be ticked again.
	Running
)

type Succeeder

type Succeeder struct {
	Child Node
	// contains filtered or unexported fields
}

Succeeder always returns Success regardless of child result.

func NewSucceeder

func NewSucceeder(name string, child Node) *Succeeder

func (*Succeeder) Name

func (s *Succeeder) Name() string

func (*Succeeder) Reset

func (s *Succeeder) Reset()

func (*Succeeder) Tick

func (s *Succeeder) Tick(bb *Blackboard) Status

type Tree

type Tree struct {
	Root       Node
	Blackboard *Blackboard
}

Tree is the root container for a behavior tree.

func NewTree

func NewTree(root Node) *Tree

NewTree creates a new behavior tree with the given root node.

func (*Tree) Reset

func (t *Tree) Reset()

Reset resets the entire tree.

func (*Tree) Tick

func (t *Tree) Tick() Status

Tick runs one update cycle on the tree.

Jump to

Keyboard shortcuts

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