Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

behavior-snippets

Code snippets for behavior tree patterns. Copy-paste ready.

Patrol with threat check

from behavior_tree import Selector, Sequence, Action, Condition

tree = Selector([
    Sequence([
        Condition(lambda: see_threat(), name="Threat check"),
        Action(lambda: alert(), name="Alert"),
    ]),
    Action(lambda: patrol(), name="Patrol"),
])

Retry on failure

from behavior_tree import Repeater, Action

tree = Repeater(
    Action(lambda: try_connect(), name="Connect"),
    max_repeats=3
)

Parallel tasks

from behavior_tree import Parallel, Action

tree = Parallel([
    Action(lambda: task_a(), name="Task A"),
    Action(lambda: task_b(), name="Task B"),
], success_threshold=2)

Inverter

from behavior_tree import Inverter, Condition

tree = Inverter(
    Condition(lambda: is_daytime(), name="Daytime check")
)
# Returns SUCCESS at night, FAILURE during day

Forage behavior

from behavior_tree import Sequence, Condition, Action

tree = Sequence([
    Condition(lambda: is_hungry(), name="Hunger check"),
    Action(lambda: find_food(), name="Find food"),
    Action(lambda: eat(), name="Eat"),
])

License

Public domain. Use in your projects.

About

Code snippets for behavior tree patterns. Copy-paste ready.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors