-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.go
More file actions
36 lines (29 loc) · 773 Bytes
/
tree.go
File metadata and controls
36 lines (29 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package behavior
import "fmt"
// "y3pp/log"
type BehaviorTree struct {
id string
title string
root *Wrapper
nodelist []Wrapper
}
func (tree *BehaviorTree) String() string {
return fmt.Sprintf("{%s}", tree.root.String())
}
func (tree *BehaviorTree) Tick(bb *Blackboard) BehaviorStatus {
// log.Info().Msg("BehaviorTree tick")
// log.Info().Msgf("root is %+v", tree.root)
if bb == nil {
return StatusFailed
}
status := tree.root.Execute(bb)
// log.Logger.Debug().Int("status", int(status)).Msg("BehaviorTree tick")
return status
}
func (tree *BehaviorTree) NewBlackboard() *Blackboard {
bb := newBlackboard(len(tree.nodelist))
for i := 0; i < len(tree.nodelist); i++ {
bb.nodeMemo[i] = tree.nodelist[i].Node.CreateMemo()
}
return bb
}