Skip to content

Instantly share code, notes, and snippets.

@ivey
Created December 29, 2014 22:27
Show Gist options
  • Save ivey/b34177cb7e9d4111583a to your computer and use it in GitHub Desktop.
Save ivey/b34177cb7e9d4111583a to your computer and use it in GitHub Desktop.
behavior_tree_builder.go
b := gobt.NewTreeBuilder()
tree := b.Tree("test",
b.Sequence("try some things",
b.Selector("1 of 3",
b.Action("fail at something",
func(player interface{}, bb *gobt.Blackboard) bool {
fmt.Println("a1: ", bb)
return false
}),
b.Action("fail at something else",
func(player interface{}, bb *gobt.Blackboard) bool {
fmt.Println("a2: ", bb)
return false
}),
b.Action("succeed",
func(player interface{}, bb *gobt.Blackboard) bool {
fmt.Println("a3: woot!")
return true
},
),
),
),
)
tree2 := b.Tree("test").
Sequence("try some things").
Selector("1 of 3").
Action("fail at something",
func(player interface{}, bb *gobt.Blackboard) bool {
fmt.Println("a1: ", bb)
return false
}).
Action("fail at something else",
func(player interface{}, bb *gobt.Blackboard) bool {
fmt.Println("a2: ", bb)
return false
}).
Action("succeed",
func(player interface{}, bb *gobt.Blackboard) bool {
fmt.Println("a3: woot!")
return true
}).
Build()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment