behavior_tree.cr
This library is an implementation of Behavior Tree for Crystal.
Installation
Add this to your application's shard.yml
:
dependencies:
behavior_tree:
github: TobiasGSmollett/behavior_tree.cr
Usage
require "behavior_tree"
include BehaviorTree
include BehaviorTree::DSL(Nil, Nil)
puts_action =
action "Puts" do |state|
puts "hello"
{true, nil}
end
predicate = ->(state : Nil){ false }
success =
action "Puts" do |state|
puts "true"
{true, nil}
end
failure =
action "Puts" do |state|
puts "false"
{true, nil}
end
result =
behavior_tree(nil,
sequence [
puts_action,
puts_action,
puts_action,
conditional(predicate, success, failure),
]
).run()
puts result
# hello
# hello
# hello
# false
# [{"Puts", nil}, {"Puts", nil}, {"Puts", nil}, {"Puts", nil}]
Contributing
- Fork it ( https://github.com/TobiasGSmollett/behavior_tree.cr/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- TobiasGSmollett TobiasGSmollett - creator, maintainer