behavior_tree 0.1.6 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/Gemfile.lock +2 -2
- data/README.md +809 -23
- data/Rakefile +77 -0
- data/behavior_tree.gemspec +4 -4
- data/lib/behavior_tree.rb +3 -3
- data/lib/behavior_tree/builder.rb +15 -45
- data/lib/behavior_tree/concerns/dsl/randomizer.rb +78 -0
- data/lib/behavior_tree/concerns/dsl/registration.rb +35 -0
- data/lib/behavior_tree/concerns/dsl/spell_checker.rb +2 -0
- data/lib/behavior_tree/concerns/dsl/utils.rb +22 -0
- data/lib/behavior_tree/concerns/tree_structure/printer.rb +31 -8
- data/lib/behavior_tree/control_nodes/control_node_base.rb +0 -2
- data/lib/behavior_tree/decorator_nodes/condition.rb +0 -1
- data/lib/behavior_tree/decorator_nodes/inverter.rb +0 -2
- data/lib/behavior_tree/decorator_nodes/repeat_times_base.rb +0 -4
- data/lib/behavior_tree/decorator_nodes/repeater.rb +0 -2
- data/lib/behavior_tree/errors.rb +8 -0
- data/lib/behavior_tree/node_base.rb +22 -10
- data/lib/behavior_tree/node_status.rb +1 -1
- data/lib/behavior_tree/single_child_node.rb +0 -3
- data/lib/behavior_tree/tasks/task_base.rb +0 -3
- data/lib/behavior_tree/tree.rb +0 -3
- data/lib/behavior_tree/version.rb +1 -1
- metadata +11 -8
data/lib/behavior_tree/errors.rb
CHANGED
@@ -62,4 +62,12 @@ module BehaviorTree
|
|
62
62
|
super "Cannot register node '#{node_type}', it already exists."
|
63
63
|
end
|
64
64
|
end
|
65
|
+
|
66
|
+
# Exception for when the returned value in should_tick? is not a boolean.
|
67
|
+
class ShouldTickNotBooleanError < StandardError
|
68
|
+
def initialize(returned_value)
|
69
|
+
err = "Return of 'should_tick?' must be a boolean value. It returned #{returned_value} (#{returned_value.class})."
|
70
|
+
super err
|
71
|
+
end
|
72
|
+
end
|
65
73
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative './concerns/tree_structure/algorithms'
|
4
|
-
|
5
3
|
module BehaviorTree
|
6
4
|
# A node (abstract class).
|
7
5
|
class NodeBase
|
8
6
|
include TreeStructure::Algorithms
|
9
|
-
attr_reader :status, :tick_count, :ticks_running, :arbitrary_storage
|
7
|
+
attr_reader :status, :prev_status, :tick_count, :ticks_running, :arbitrary_storage
|
10
8
|
|
11
9
|
def initialize
|
12
10
|
@status = NodeStatus.new NodeStatus::SUCCESS
|
11
|
+
@prev_status = NodeStatus.new NodeStatus::SUCCESS
|
12
|
+
|
13
13
|
@tick_count = 0
|
14
14
|
@ticks_running = 0
|
15
15
|
@context = nil
|
16
16
|
|
17
|
-
@status.subscribe { |prev
|
17
|
+
@status.subscribe { |prev| __on_status_change__(prev) }
|
18
18
|
|
19
19
|
@arbitrary_storage = {}
|
20
20
|
end
|
@@ -34,9 +34,10 @@ module BehaviorTree
|
|
34
34
|
|
35
35
|
def tick!
|
36
36
|
@tick_count += 1
|
37
|
-
|
37
|
+
should_tick = should_tick?
|
38
|
+
raise ShouldTickNotBooleanError, should_tick unless [true, false].include? should_tick
|
38
39
|
|
39
|
-
unless @tick_prevented
|
40
|
+
unless (@tick_prevented = !should_tick)
|
40
41
|
status.running!
|
41
42
|
on_tick
|
42
43
|
@ticks_running += 1
|
@@ -49,6 +50,9 @@ module BehaviorTree
|
|
49
50
|
#
|
50
51
|
# This error can be replicated by pasting a valid status object in IRB, such as by doing:
|
51
52
|
# BehaviorTree.const_get(:NodeStatus).new(:__running__) # Valid, but IRB crashes.
|
53
|
+
#
|
54
|
+
# Ruby 3.0.0 -> Crash
|
55
|
+
# Ruby 2.7.0 -> OK
|
52
56
|
nil
|
53
57
|
end
|
54
58
|
|
@@ -100,18 +104,26 @@ module BehaviorTree
|
|
100
104
|
|
101
105
|
def on_finished_running; end
|
102
106
|
|
107
|
+
def on_status_change; end
|
108
|
+
|
103
109
|
private
|
104
110
|
|
105
|
-
# Always prev !=
|
111
|
+
# Always prev != current (states that are set to the same aren't notified).
|
106
112
|
# The fact that it's set to 0 means that setting to running must be done before
|
107
113
|
# increasing the counts (so that @ticks_running becomes 1 after the whole tick lifecycle).
|
108
|
-
|
109
|
-
|
114
|
+
# This is the non custom on_status_change. Users are expected to override the one without
|
115
|
+
# double underscore if they want to execute custom logic.
|
116
|
+
def __on_status_change__(prev)
|
117
|
+
prev_status.set(prev)
|
118
|
+
|
119
|
+
if prev_status.running?
|
110
120
|
on_finished_running
|
111
|
-
elsif
|
121
|
+
elsif status.running?
|
112
122
|
@ticks_running = 0
|
113
123
|
on_started_running
|
114
124
|
end
|
125
|
+
|
126
|
+
on_status_change
|
115
127
|
end
|
116
128
|
end
|
117
129
|
|
data/lib/behavior_tree/tree.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: behavior_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felo Vilches
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.8.1
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- felovilches@gmail.com
|
30
30
|
executables: []
|
@@ -48,7 +48,10 @@ files:
|
|
48
48
|
- lib/behavior_tree/builder.rb
|
49
49
|
- lib/behavior_tree/concerns/dsl/dsl.yml
|
50
50
|
- lib/behavior_tree/concerns/dsl/initial_config.rb
|
51
|
+
- lib/behavior_tree/concerns/dsl/randomizer.rb
|
52
|
+
- lib/behavior_tree/concerns/dsl/registration.rb
|
51
53
|
- lib/behavior_tree/concerns/dsl/spell_checker.rb
|
54
|
+
- lib/behavior_tree/concerns/dsl/utils.rb
|
52
55
|
- lib/behavior_tree/concerns/node_iterators/all_nodes.rb
|
53
56
|
- lib/behavior_tree/concerns/node_iterators/prioritize_running.rb
|
54
57
|
- lib/behavior_tree/concerns/tree_structure/algorithms.rb
|
@@ -79,7 +82,7 @@ homepage: https://github.com/FeloVilches/Ruby-Behavior-Tree
|
|
79
82
|
licenses:
|
80
83
|
- MIT
|
81
84
|
metadata: {}
|
82
|
-
post_install_message:
|
85
|
+
post_install_message:
|
83
86
|
rdoc_options: []
|
84
87
|
require_paths:
|
85
88
|
- lib
|
@@ -94,8 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
97
|
- !ruby/object:Gem::Version
|
95
98
|
version: '0'
|
96
99
|
requirements: []
|
97
|
-
rubygems_version: 3.
|
98
|
-
signing_key:
|
100
|
+
rubygems_version: 3.2.3
|
101
|
+
signing_key:
|
99
102
|
specification_version: 4
|
100
|
-
summary:
|
103
|
+
summary: A robust and customizable Ruby gem for creating Behavior Trees.
|
101
104
|
test_files: []
|