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 ¶
- type Action
- type Blackboard
- func (b *Blackboard) Delete(key string)
- func (b *Blackboard) Get(key string) (interface{}, bool)
- func (b *Blackboard) GetBool(key string) bool
- func (b *Blackboard) GetFloat(key string) float64
- func (b *Blackboard) GetInt(key string) int
- func (b *Blackboard) GetString(key string) string
- func (b *Blackboard) Set(key string, val interface{})
- type Condition
- type DynamicNode
- type Inverter
- type Node
- type Parallel
- type Repeater
- type Selector
- type Sequence
- type Status
- type Succeeder
- type Tree
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 (*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 (*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.
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) 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 (*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 (*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 (*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 (*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 (*Sequence) Tick ¶
func (s *Sequence) Tick(bb *Blackboard) Status
type Succeeder ¶
type Succeeder struct {
Child Node
// contains filtered or unexported fields
}
Succeeder always returns Success regardless of child result.
func NewSucceeder ¶
func (*Succeeder) Tick ¶
func (s *Succeeder) Tick(bb *Blackboard) Status