class BehaviorTree::Decorators::RepeatTimesBase
While the node status is <repeat_while>, tick it again up to N times. Interrupt the loop when the <repeat_while> condition fails. If the child returns running, this node returns running too. The count is resetted when the loop is interrupted or finished. N is the total times to be ticked, and it includes the initial tick (the original tick that all nodes have in common).
Public Class Methods
new(child, max)
click to toggle source
Calls superclass method
# File lib/behavior_tree/decorator_nodes/repeat_times_base.rb, line 12 def initialize(child, max) validate_max!(max) super(child) @max = max reset_remaining_attempts end
Public Instance Methods
decorate()
click to toggle source
# File lib/behavior_tree/decorator_nodes/repeat_times_base.rb, line 20 def decorate while repeat_while || child.status.running? break if child.status.running? @remaining_attempts -= 1 break unless @remaining_attempts.positive? child.tick! break if child.status.running? end end
Protected Instance Methods
repeat_while()
click to toggle source
# File lib/behavior_tree/decorator_nodes/repeat_times_base.rb, line 34 def repeat_while raise NotImplementedError end
Private Instance Methods
reset_remaining_attempts()
click to toggle source
# File lib/behavior_tree/decorator_nodes/repeat_times_base.rb, line 40 def reset_remaining_attempts @remaining_attempts = @max end
validate_max!(max)
click to toggle source
# File lib/behavior_tree/decorator_nodes/repeat_times_base.rb, line 44 def validate_max!(max) return if max.is_a?(Integer) && max.positive? raise ArgumentError, 'Number of repetitions must be a positive integer.' end