Class: BehaviorTree::ControlNodeBase
- Inherits:
-
NodeBase
- Object
- NodeBase
- BehaviorTree::ControlNodeBase
- Defined in:
- lib/behavior_tree/control_nodes/control_node_base.rb
Overview
A node that has children (abstract class).
Class Method Summary collapse
Instance Method Summary collapse
- #<<(child) ⇒ Object
- #halt! ⇒ Object
-
#initialize(children = []) ⇒ ControlNodeBase
constructor
A new instance of ControlNodeBase.
Methods included from NodeIterators::AllNodes
Methods included from TreeStructure::Algorithms
#cycle?, #each_node, #repeated_nodes, #uniq_nodes?
Constructor Details
#initialize(children = []) ⇒ ControlNodeBase
Returns a new instance of ControlNodeBase.
11 12 13 14 15 16 17 |
# File 'lib/behavior_tree/control_nodes/control_node_base.rb', line 11 def initialize(children = []) raise IncorrectTraversalStrategyError, nil.class if traversal_strategy.nil? raise IncorrectTraversalStrategyError, traversal_strategy unless respond_to?(traversal_strategy, true) super() @children = children end |
Class Method Details
.traversal_strategy ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/behavior_tree/control_nodes/control_node_base.rb', line 71 def traversal_strategy @traversal_strategy ||= ancestors.find do |constant| next if constant == self next unless constant.is_a? Class next unless constant.respond_to? :traversal_strategy next if constant.traversal_strategy.nil? break constant.traversal_strategy end end |
Instance Method Details
#<<(child) ⇒ Object
19 20 21 22 23 |
# File 'lib/behavior_tree/control_nodes/control_node_base.rb', line 19 def <<(child) @children << child @children.flatten! # Accepts array of children too. @children.map!(&:chainable_node) end |
#halt! ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/behavior_tree/control_nodes/control_node_base.rb', line 25 def halt! validate_non_leaf! super @children.each(&:halt!) end |