Struct aspen::std_nodes::Parallel
[−]
[src]
pub struct Parallel { /* fields omitted */ }
A node that handles "concurrent" behavior.
Every tick, this node will tick all of its children that have not been run to completion. Success or failure of this node is determined by how many of its children are in a successful or failed state. If the specified number of children have succeeded, this node succeeds. If it is impossible for the remaining children to bring the success count to the required threshold then the node fails. Otherwise it is considered running.
Note that a threshold of zero means this node always succeeds on the first tick and a threshold greater than the number of children means this node always fails on the first tick.
It is also important to note that this node can cause child Action
nodes
to actually run in parallel.
State
Initialized: Before being ticked after either being created or reset.
Running: As long as the successful child count is below the threshold and the running children could potentially make the successful count cross the threshold.
Succeeded: The count of successful children is greater than the threshold.
Failed: The sum of the successful children and the running children is smaller than the threshold.
Children
Any number. The children will be reset when this node is reset but may not necessarily ticked when this node is, depending on their current status.
There is a possibility that some children may not be ticked to completion
based on when the Parallel
node crosses its success or failure threshold.
Examples
A node that has enough successful children:
let threshold = 3; let mut node = Parallel::new(vec![ AlwaysSucceed::new(), AlwaysSucceed::new(), AlwaysSucceed::new(), AlwaysRunning::new(), AlwaysFail::new() ], threshold); assert_eq!(node.tick(), Status::Succeeded);
A node that could either succeed or fail, so it is still running:
let threshold = 3; let mut node = Parallel::new(vec![ AlwaysSucceed::new(), AlwaysSucceed::new(), AlwaysRunning::new(), AlwaysRunning::new(), AlwaysFail::new() ], threshold); assert_eq!(node.tick(), Status::Running);
A node that could not possibly succeed, so it fails:
let threshold = 4; let mut node = Parallel::new(vec![ AlwaysSucceed::new(), AlwaysSucceed::new(), AlwaysRunning::new(), AlwaysFail::new(), AlwaysFail::new() ], threshold); assert_eq!(node.tick(), Status::Failed);
Methods
impl Parallel
[src]
fn new(children: Vec<Node>, required_successes: usize) -> Node
Creates a Parallel
node with the given children an required number of successes.
Trait Implementations
impl Internals for Parallel
[src]
fn tick(&mut self) -> Status
Ticks the internal state of the node a single time. Read more
fn reset(&mut self)
Resets the internal state of the node. Read more
fn children(&self) -> Option<Vec<&Node>>
Returns a vector of references to this node's children. Read more
fn type_name(&self) -> &'static str
Returns the string "Parallel".