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 NodeIterators::PrioritizeRunning
Methods included from TreeStructure::Algorithms
#cycle?, #each_node, #repeated_nodes, #uniq_nodes?
Constructor Details
#initialize(children = []) ⇒ ControlNodeBase
Returns a new instance of ControlNodeBase.
13 14 15 16 17 18 19 |
# File 'lib/behavior_tree/control_nodes/control_node_base.rb', line 13 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
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/behavior_tree/control_nodes/control_node_base.rb', line 73 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
21 22 23 24 25 |
# File 'lib/behavior_tree/control_nodes/control_node_base.rb', line 21 def <<(child) @children << child @children.flatten! # Accepts array of children too. @children.map!(&:chainable_node) end |
#halt! ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/behavior_tree/control_nodes/control_node_base.rb', line 27 def halt! validate_non_leaf! super @children.each(&:halt!) end |