gobehaviortree

package module
v0.0.0-...-c8bcd0e Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 0 Imported by: 0

README

Introduction

AI behavior tree base on golang implement.

基于Golang实现的ai行为树。

Usage

Look at test package example.

看看test包的使用例子就知道了。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AINode

type AINode struct {
	ChildCount int
	Parent     BaseNode

	IdxInParent int
	Name        string
	Tree        *Tree
	// contains filtered or unexported fields
}

AINode node describe

func (*AINode) GetIdx

func (a *AINode) GetIdx() int

func (*AINode) SetIdx

func (a *AINode) SetIdx(idx int)

func (*AINode) SetParent

func (a *AINode) SetParent(parent BaseNode)

func (*AINode) SetTree

func (a *AINode) SetTree(tree *Tree)

SetTree don't delete

func (*AINode) WhoAmI

func (a *AINode) WhoAmI() string

type BaseNode

type BaseNode interface {
	SetParent(parent BaseNode)
	SetIdx(idx int)
	GetIdx() int
	Print()
	WhoAmI() string
	SetTree(t *Tree)

	OnInstall()
	OnUninstall()
	OnEnter() Result
	OnExit()
}

BaseNode baseNode

type OnExecTreeFunc

type OnExecTreeFunc func(tree *Tree)

type OnTreeChildFinishFunc

type OnTreeChildFinishFunc func(tree *Tree, result Result, root BaseNode)

type Result

type Result int

Result result enums

const (
	ResultNil Result = iota
	ResultFailed
	ResultSuccess
	ResultRunning
)

type SelectAINode

type SelectAINode struct {
	AINode
}

SequenceAINode sequence node

func NewSelector

func NewSelector() *SelectAINode

NewSequence construct

func (*SelectAINode) AddNodes

func (s *SelectAINode) AddNodes(nodes ...BaseNode)

AddNode add node

func (*SelectAINode) OnEnter

func (s *SelectAINode) OnEnter() Result

OnEnter enter

func (*SelectAINode) OnExit

func (s *SelectAINode) OnExit()

OnExit exit

func (*SelectAINode) OnInstall

func (s *SelectAINode) OnInstall()

OnInstall preEnter

func (*SelectAINode) OnUninstall

func (s *SelectAINode) OnUninstall()

OnUninstall uninstall

func (*SelectAINode) Print

func (s *SelectAINode) Print()

Print dump all

func (*SelectAINode) SetIdx

func (s *SelectAINode) SetIdx(idx int)

SetIdx setidx

func (*SelectAINode) SetParent

func (s *SelectAINode) SetParent(parent BaseNode)

SetParent set parent

func (*SelectAINode) WhoAmI

func (s *SelectAINode) WhoAmI() (am string)

WhoAmI return ownerself

type SequenceAINode

type SequenceAINode struct {
	AINode
}

SequenceAINode sequence node

func NewSequence

func NewSequence() *SequenceAINode

NewSequence construct

func (*SequenceAINode) AddNodes

func (s *SequenceAINode) AddNodes(nodes ...BaseNode)

AddNode add node

func (*SequenceAINode) OnEnter

func (s *SequenceAINode) OnEnter() Result

OnEnter enter

func (*SequenceAINode) OnExit

func (s *SequenceAINode) OnExit()

OnExit exit

func (*SequenceAINode) OnInstall

func (s *SequenceAINode) OnInstall()

OnInstall preEnter

func (*SequenceAINode) OnUninstall

func (s *SequenceAINode) OnUninstall()

OnUninstall uninstall

func (*SequenceAINode) Print

func (s *SequenceAINode) Print()

Print dump all

func (*SequenceAINode) SetIdx

func (s *SequenceAINode) SetIdx(idx int)

SetIdx setidx

func (*SequenceAINode) SetParent

func (s *SequenceAINode) SetParent(parent BaseNode)

SetParent set parent

func (*SequenceAINode) WhoAmI

func (s *SequenceAINode) WhoAmI() (am string)

WhoAmI return ownerself

type Tree

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

Tree tree describe

func NewTree

func NewTree(onExec OnExecTreeFunc, onChildFinish OnTreeChildFinishFunc) *Tree

NewTree new tree

func (*Tree) GetRoot

func (t *Tree) GetRoot() BaseNode

func (*Tree) Run

func (t *Tree) Run()

Run run

func (*Tree) SetRoot

func (t *Tree) SetRoot(node BaseNode)

SetRoot setroot

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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