aitree

package module
v0.0.0-...-95ff2eb Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2022 License: GPL-3.0 Imports: 0 Imported by: 2

README

Simple behavior tree in Golang (WIP)

This is a very, very simple behavior tree that does the basic basics. It's not meant to be used in production, but it is probably good for tinkering around and learning how those things behave and whatnot.

Principle

I'll write something here some day when this is done.

IOU

Proper documentation whenever this is finished.

Documentation

Overview

Package aitree implements a very basic behavior tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ForceFailure

type ForceFailure struct {
	Name  string
	Child Node
}

ForceFailure returns failure on completion.

func NewForceFailure

func NewForceFailure(name string, child Node) *ForceFailure

NewForceFailure returns a new ForceFailure decorator.

func (*ForceFailure) Tick

func (node *ForceFailure) Tick() State

Tick will execute the child and return failure on completion.

type ForceSuccess

type ForceSuccess struct {
	Name  string
	Child Node
}

ForceSuccess returns success on completion.

func NewForceSuccess

func NewForceSuccess(name string, child Node) *ForceSuccess

NewForceSuccess returns a new ForceSuccess decorator.

func (*ForceSuccess) Tick

func (node *ForceSuccess) Tick() State

Tick will execute the child and return success on completion.

type Inverter

type Inverter struct {
	Name  string
	Child Node
}

Inverter implements an inverter decorator (success on failure and vice versa).

func NewInverter

func NewInverter(name string, child Node) *Inverter

NewInverter returns a new Inverter decorator.

func (*Inverter) Tick

func (node *Inverter) Tick() State

Tick will execute the child and return success on failure and vice versa.

type Node

type Node interface {
	Tick() State
}

Node represents a node within the tree.

type Repeater

type Repeater struct {
	Name     string
	Child    Node
	Current  int
	Attempts int
}

Repeater implements a repeater logic decorator.

func NewRepeater

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

NewRepeater returns a new repeater decorator.

func (*Repeater) Tick

func (node *Repeater) Tick() State

Tick will execute the child up to n times and will return success if all attempts succeed.

type Retry

type Retry struct {
	Name     string
	Child    Node
	Current  int
	Attempts int
}

Retry implements a retry logic decorator.

func NewRetry

func NewRetry(name string, child Node, n int) *Retry

NewRetry returns a new retry decorator.

func (*Retry) Tick

func (node *Retry) Tick() State

Tick will attempt up to n times to execute the child until it succeeds or will return failure if the retries are exhausted.

type Selector

type Selector struct {
	Name     string
	Children []Node
	Current  int // Current active child node
}

Selector implements a selector decorator node.

func NewSelector

func NewSelector(name string) *Selector

NewSelector returns a new selector decorator node.

func (*Selector) Append

func (node *Selector) Append(c Node)

Append a new child node.

func (*Selector) Tick

func (node *Selector) Tick() State

Tick will attempt to run each child sequentially and returns success if one of them succeeds.

type Sequence

type Sequence struct {
	Name     string
	Children []Node
	Current  int // Current active child node
}

Sequence implements a sequence decorator node.

func NewSequence

func NewSequence(name string) *Sequence

NewSequence returns a new sequence decorator node.

func (*Sequence) Append

func (node *Sequence) Append(c Node)

Append a new child node.

func (*Sequence) Tick

func (node *Sequence) Tick() State

Tick will attempt to run all children in the sequence and returns success if all complete successfully.

type State

type State int

State represents the outcome of an operation

const (
	StateRunning State = iota
	StateFailure
	StateSuccess
)

Valid outcomes.

type Tree

type Tree struct {
	Root Node
}

Tree implements a simple behavior tree.

func New

func New() *Tree

New returns a new tree.

func (*Tree) Tick

func (t *Tree) Tick() State

Tick will advance the tree by a single tick.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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