![]() |
CUGL 1.2
Cornell University Game Library
|
#include <CURandomNode.h>
Public Member Functions | |
RandomNode () | |
~RandomNode () | |
bool | init (const std::string &name, std::minstd_rand *generator) |
void | dispose () override |
bool | isUniform () const |
void | setUniform (bool uniform) |
std::string | toString (bool verbose=false) const override |
virtual void | query (float dt) override |
![]() | |
CompositeNode () | |
~CompositeNode () | |
bool | isPreemptive () const |
void | setPreemptive (bool preemptive) |
const BehaviorNode * | getChildByPriorityIndex (Uint32 index) const |
template<typename T > | |
const T * | getChildByPriorityIndex (Uint32 index) const |
const BehaviorNode * | getActiveChild () const |
template<typename T > | |
const T * | getActiveChild () const |
BehaviorNode::State | update (float dt) override |
![]() | |
BehaviorNode () | |
~BehaviorNode () | |
bool | init (const std::string &name) |
const std::string & | getName () const |
float | getPriority () const |
BehaviorNode::State | getState () const |
virtual void | setState (BehaviorNode::State state) |
std::function< float()> | getPrioritizer () const |
void | setPrioritizer (const std::function< float()> &func) |
operator std::string () const | |
const BehaviorNode * | getParent () const |
void | setParent (BehaviorNode *parent) |
void | removeFromParent () |
int | getParentalOffset () const |
size_t | getChildCount () const |
std::vector< const BehaviorNode * > | getChildren () const |
const BehaviorNode * | getChild (Uint32 pos) const |
template<typename T > | |
const T * | getChild (Uint32 pos) const |
const BehaviorNode * | getNodeByName (const std::string &name) const |
const BehaviorNode * | getNodeByName (const char *name) const |
template<typename T > | |
const T * | getNodeByName (const std::string &name) const |
template<typename T > | |
const T * | getNodeByName (const char *name) const |
virtual void | reset () |
virtual void | pause () |
virtual void | resume () |
virtual void | preempt () |
virtual void | start () |
void | setPriority (float priority) |
std::shared_ptr< BehaviorNode > | removeChild (Uint32 pos) |
void | addChild (const std::shared_ptr< BehaviorNode > child) |
Protected Member Functions | |
virtual int | selectChild () const override |
Protected Attributes | |
bool | _uniform |
std::minstd_rand * | _generator |
![]() | |
bool | _preemptive |
![]() | |
std::string | _name |
std::string | _classname |
BehaviorNode * | _parent |
BehaviorNode::State | _state |
float | _priority |
std::function< float()> | _prioritizer |
std::vector< std::shared_ptr< BehaviorNode > > | _children |
int | _activeChild |
int | _childOffset |
Additional Inherited Members | |
![]() | |
enum | State : unsigned int { State::INACTIVE = 0, State::RUNNING = 1, State::PAUSED = 2, State::FINISHED = 3 } |
![]() | |
static bool | compareSiblings (const std::shared_ptr< BehaviorNode > &a, const std::shared_ptr< BehaviorNode > &b) |
This class provides a random composite node for a behavior tree.
A random node is a composite node that is designed to run a randomly selected nodes out of its children, based on either a uniform probability or a weighted probability. A random node using a weighted probability will base the weights of the probability of selecting each child on the priority of that child.
If a random node is not given a priority function, it will set its priority as the average of the priorities of its children.
A random node's state is directly based upon the child node currently running or the child node that has finished running. Only one child node will finish running as part of the RandomNode.
cugl::ai::RandomNode::RandomNode | ( | ) |
Creates an uninitialized random node.
You should never call this constructor directly. Instead, you should allocate a node with the BehaviorManager instance.
|
inline |
Deletes this node, disposing all resources.
|
overridevirtual |
Disposes all of the resources used by this node, including any descendants.
A disposed node can be safely reinitialized. Any children owned by this node will be released. They will be deleted if no other object owns them. This method should only be called by BehaviorManager.
Reimplemented from cugl::ai::CompositeNode.
bool cugl::ai::RandomNode::init | ( | const std::string & | name, |
std::minstd_rand * | generator | ||
) |
Initializes a random node with the given name and generator.
The generator is provided by BehaviorManager. You should never call this method directly. Instead, you should initialize a node with the BehaviorManager instance.
name | The name of the random node |
generator | The random number generator |
|
inline |
Returns true if this node chooses uniformly at random.
If true, then this node chooses its child uniformly at random. Otherwise, this node uses a weighted probability among its children based on each child's priority value.
|
overridevirtual |
Updates the priority value(s) for this node.
This method recursively determines the priority of this node and all of its children. The priority may be determined by a user-provided priority function or by the default priority function of the class.
When this method is complete, it will chose a child node to run, but will not run it. Unlike update, this method is guaranteed to run every time step in BehaviorManager, provided that the root node is running.
dt | The elapsed time since the last frame. |
Reimplemented from cugl::ai::CompositeNode.
|
overrideprotectedvirtual |
Returns a (possibly new) active child for this node.
This method is subclass dependent, and uses the rules of that subclass to select a child. If no child is selected, this method returns -1.
Implements cugl::ai::CompositeNode.
|
inline |
Returns true if this node chooses uniformly at random.
If true, then this node chooses its child uniformly at random. Otherwise, this node uses a weighted probability among its children based on each child's priority value.
|
overridevirtual |
Returns a string representation of this node for debugging purposes.
If verbose is true, the string will include class information. This allows us to unambiguously identify the class.
verbose | Whether to include class information. |
Reimplemented from cugl::ai::BehaviorNode.
|
protected |
A reference to the behavior tree manager's random generator
|
protected |
Whether this node should choose a child uniformly at random.