write an example using github.com/joeycumines/go-behaviortree
- User
write an example using github.com/joeycumines/go-behaviortree
- Assistant
Here's an example of using the
github.com/joeycumines/go-behaviortreepackage to create a simple behavior tree:package main import ( "fmt" bt "github.com/joeycumines/go-behaviortree" ) func main() { // Create the root node of the behavior tree root := bt.NewSelectorNode( "Root", // Add child nodes to the root bt.NewSequenceNode("Sequence", bt.NewConditionNode("Condition1", func() bool { // Perform some condition check here return true }), bt.NewActionNode("Action1", func() bt.Status { // Perform an action here fmt.Println("Performing Action1...") return bt.Success }), ), bt.NewActionNode("Action2", func() bt.Status { // Perform another action here fmt.Println("Performing Action2...") return bt.Success }), ) // Execute the behavior tree status := root.Tick() if status == bt.Success { fmt.Println("Behavior tree executed successfully!") } else if status == bt.Failure { fmt.Println("Behavior tree execution failed!") } else if status == bt.Running { fmt.Println("Behavior tree execution is still running!") } else { fmt.Println("Unknown status returned by behavior tree!") } }