composite

package
v1.1.23 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IChildrenOrder

type IChildrenOrder interface {
	// OnOrder 为孩子节点索引排序, NonParallel.OnStart 里回调
	//  @param originChildrenOrder
	//  @return orders 排序后的索引
	//  @return needOrder 是否需要排序
	OnOrder(brain bcore.IBrain, originChildrenOrder []int) (orders []int, needOrder bool)
}

type INonParallelWorker

type INonParallelWorker interface {
	IChildrenOrder
	// SuccessMode  成功模式
	//  @return behavior.FinishMode
	SuccessMode() bcore.FinishMode
}

INonParallelWorker 继承 NonParallel 时必须实现的接口

type IParallelProperties

type IParallelProperties interface {
	GetSuccessPolicy() bcore.FinishMode
	GetFailurePolicy() bcore.FinishMode
}

type IRandomCompositeProperties

type IRandomCompositeProperties interface {
	GetWeight() []int
}

type NonParallel

type NonParallel struct {
	bcore.Composite
	INonParallelWorker
	// contains filtered or unexported fields
}

NonParallel 非并行组合基类,节点按从左到右的顺序执行其子节点

func (*NonParallel) AbortLowerPriorityChildrenForChild

func (n *NonParallel) AbortLowerPriorityChildrenForChild(brain bcore.IBrain, childAbortBy bcore.INode)

AbortLowerPriorityChildrenForChild

@implement IComposite.AbortLowerPriorityChildrenForChild
@receiver c
@param childAbortBy

func (*NonParallel) CurrChild

func (n *NonParallel) CurrChild(brain bcore.IBrain) bcore.INode

CurrChild 当前处理的子节点

@receiver n
@param brain
@return behavior.INode

func (*NonParallel) CurrChildIdx

func (n *NonParallel) CurrChildIdx(brain bcore.IBrain) int

CurrChildIdx 当前处理的子节点index

@receiver n
@param brain
@return int

func (*NonParallel) CurrIdx

func (n *NonParallel) CurrIdx(brain bcore.IBrain) int

CurrIdx 当前处理进度index

@receiver n
@param brain
@return int

func (*NonParallel) InitNodeWorker

func (n *NonParallel) InitNodeWorker(worker bcore.INodeWorker) error

InitNodeWorker

@override Node.InitNodeWorker
@receiver c
@param worker

func (*NonParallel) OnAbort

func (n *NonParallel) OnAbort(brain bcore.IBrain)

OnAbort

@override Node.OnAbort
@receiver n
@param brain

func (*NonParallel) OnChildFinished

func (n *NonParallel) OnChildFinished(brain bcore.IBrain, child bcore.INode, succeeded bool)

OnChildFinished

 Sequence 碰到一个失败就Finish(false)
 Selector 碰到一个成功就Finish(true)
 若是被父节点中断的,马上Finish(false)

	@override Container.OnChildFinished
	@receiver r
	@param brain
	@param child
	@param succeeded

func (*NonParallel) OnOrder

func (n *NonParallel) OnOrder(brain bcore.IBrain, originChildrenOrder []int) (orders []int, needOrder bool)

OnOrder

@implement INonParallelWorker.OnOrder
@receiver n
@param originChildrenOrder
@return orders
@return needOrder

func (*NonParallel) OnStart

func (n *NonParallel) OnStart(brain bcore.IBrain)

OnStart

@override Node.OnStart
@receiver n
@param brain

func (*NonParallel) OnString

func (n *NonParallel) OnString(brain bcore.IBrain) string

func (*NonParallel) SetCurrIdx

func (n *NonParallel) SetCurrIdx(brain bcore.IBrain, currChild int)

type Parallel

type Parallel struct {
	bcore.Composite
}

Parallel 并行组合基类,节点按从左到右的顺序根据结束模式决定完成时机

并行执行所有子节点,根据成功原则和失败原则,决定节点停用时机
| 成功原则 | 失败原则 |
| ParallelProperties.SuccessPolicy | ParallelProperties.FailurePolicy |

| behavior.FinishModeOne | behavior.FinishModeOne |
第一个子节点停用返回true(false)后,关闭所有子节点,停用当前节点返回true(false)

| behavior.FinishModeOne | behavior.FinishModeAll |
当有一个子节点停用返回true后,关闭所有子节点,停用当前节点返回true,否则返回false

| behavior.FinishModeAll | behavior.FinishModeOne |
所有子节点停用返回true后,当前节点停用返回true,否则返回false

| behavior.FinishModeAll | behavior.FinishModeAll |
所有子节点停用返回true后,当前节点停用返回true,否则返回false

func (*Parallel) AbortLowerPriorityChildrenForChild

func (p *Parallel) AbortLowerPriorityChildrenForChild(brain bcore.IBrain, childAbortBy bcore.INode)

AbortLowerPriorityChildrenForChild

@implement IComposite.AbortLowerPriorityChildrenForChild
@receiver c
@param childAbortBy

func (*Parallel) OnAbort

func (p *Parallel) OnAbort(brain bcore.IBrain)

OnAbort

@override Node.OnAbort
@receiver n
@param brain

func (*Parallel) OnChildFinished

func (p *Parallel) OnChildFinished(brain bcore.IBrain, child bcore.INode, succeeded bool)

OnChildFinished

@override Container.OnChildFinished
@receiver r
@param brain
@param child
@param succeeded

func (*Parallel) OnStart

func (p *Parallel) OnStart(brain bcore.IBrain)

OnStart

@override Node.OnStart
@receiver n
@param brain

func (*Parallel) PMemory

func (p *Parallel) PMemory(brain bcore.IBrain) *bcore.ParallelMemory

func (*Parallel) PropertiesClassProvider

func (p *Parallel) PropertiesClassProvider() any

PropertiesClassProvider

@implement INodeWorker.PropertiesClassProvider
@receiver n
@return any

type ParallelProperties

type ParallelProperties struct {
	SuccessPolicy bcore.FinishMode `json:"successPolicy"` // 成功策略
	FailurePolicy bcore.FinishMode `json:"failurePolicy"` // 失败策略
}

ParallelProperties 平行节点属性

type RandomCompositeProperties

type RandomCompositeProperties struct {
	Weight []int `json:"weight"`
}

RandomCompositeProperties 随机组合节点属性

func (*RandomCompositeProperties) GetWeight

func (r *RandomCompositeProperties) GetWeight() []int

type RandomSelector

type RandomSelector struct {
	Selector
	// contains filtered or unexported fields
}

RandomSelector 随机选择器.节点按从左到右的随机执行其子节点。当其中一个子节点执行成功时,选择器节点将停止执行。如果选择器的一个子节点成功运行,则选择器运行成功。如果选择器的所有子节点运行失败,则选择器运行失败。

func (*RandomSelector) InitNodeWorker

func (r *RandomSelector) InitNodeWorker(worker bcore.INodeWorker) error

InitNodeWorker

@override Node.InitNodeWorker
@receiver c
@param worker

func (*RandomSelector) OnOrder

func (r *RandomSelector) OnOrder(brain bcore.IBrain, originChildrenOrder []int) (orders []int, needOrder bool)

OnOrder

@implement INonParallelWorker.OnOrder
@receiver r
@param brain
@param originChildrenOrder
@return orders
@return needOrder

func (*RandomSelector) PropertiesClassProvider

func (r *RandomSelector) PropertiesClassProvider() any

PropertiesClassProvider

@implement INodeWorker.PropertiesClassProvider
@receiver n
@return any

type RandomSequence

type RandomSequence struct {
	Sequence
	// contains filtered or unexported fields
}

RandomSequence 随机序列,节点按从左到右的顺序随机执行其子节点。当其中一个子节点失败时,序列节点也将停止执行。如果有子节点失败,那么序列就会失败。如果该序列的所有子节点运行都成功执行,则序列节点成功。

func (*RandomSequence) InitNodeWorker

func (r *RandomSequence) InitNodeWorker(worker bcore.INodeWorker) error

InitNodeWorker

@override Node.InitNodeWorker
@receiver c
@param worker

func (*RandomSequence) OnOrder

func (r *RandomSequence) OnOrder(brain bcore.IBrain, originChildrenOrder []int) (orders []int, needOrder bool)

OnOrder

@implement INonParallelWorker.OnOrder
@receiver r
@param brain
@param originChildrenOrder
@return orders
@return needOrder

func (*RandomSequence) PropertiesClassProvider

func (r *RandomSequence) PropertiesClassProvider() any

PropertiesClassProvider

@implement INodeWorker.PropertiesClassProvider
@receiver n
@return any

type RandomWorker

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

RandomWorker 组合节点随机排序的委托

func NewRandomWorker

func NewRandomWorker(node bcore.IComposite) *RandomWorker

func (*RandomWorker) OnOrder

func (r *RandomWorker) OnOrder(brain bcore.IBrain, originChildrenOrder []int) (orders []int, needOrder bool)

OnOrder

@implement INonParallelWorker.OnOrder
@receiver r
@param brain
@param originChildrenOrder
@return orders
@return needOrder

func (*RandomWorker) PropertiesClassProvider

func (r *RandomWorker) PropertiesClassProvider() any

PropertiesClassProvider

@implement INodeWorker.PropertiesClassProvider
@receiver n
@return any

type Selector

type Selector struct {
	NonParallel
}

Selector 选择器.节点按从左到右的顺序执行其子节点。当其中一个子节点执行成功时,选择器节点将停止执行。如果选择器的一个子节点成功运行,则选择器运行成功。如果选择器的所有子节点运行失败,则选择器运行失败。

func (*Selector) SuccessMode

func (s *Selector) SuccessMode() bcore.FinishMode

SuccessMode @implement INonParallelWorker.SuccessMode

@receiver s
@param brain
@return behavior.FinishMode

type Sequence

type Sequence struct {
	NonParallel
}

Sequence 序列,节点按从左到右的顺序执行其子节点。当其中一个子节点失败时,序列节点也将停止执行。如果有子节点失败,那么序列就会失败。如果该序列的所有子节点运行都成功执行,则序列节点成功。

func (*Sequence) SuccessMode

func (s *Sequence) SuccessMode() bcore.FinishMode

SuccessMode @implement INonParallelWorker.SuccessMode

@receiver s
@param brain
@return behavior.FinishMode

Jump to

Keyboard shortcuts

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