Struct Tree

Source
pub struct Tree { /* private fields */ }
Expand description

A decision tree framework for creating game AI structures.

Implementations§

Source§

impl Tree

Source

pub fn sel(nodes: &Vec<Tree>) -> Tree

Creates a selector node with the specified child nodes.

A selector node will go through the child nodes until one succeeds.

§Arguments
  • nodes - An array of Leaf nodes.
§Returns
  • A Leaf node that represents a selector.
Source

pub fn seq(nodes: &Vec<Tree>) -> Tree

Creates a sequence node with the specified child nodes.

A sequence node will go through the child nodes until all nodes succeed.

§Arguments
  • nodes - An array of Leaf nodes.
§Returns
  • A Leaf node that represents a sequence.
Source

pub fn con(name: &str, handler: Box<dyn FnMut(&Unit) -> bool>) -> Tree

Creates a condition node with the specified name and handler function.

§Arguments
  • name - The name of the condition.
  • check - The check function that takes a Unit parameter and returns a boolean result.
§Returns
  • A Leaf node that represents a condition check.
Source

pub fn act(action_name: &str) -> Tree

Creates an action node with the specified action name.

§Arguments
  • action_name - The name of the action to perform.
§Returns
  • A Leaf node that represents an action.
Source

pub fn act_dynamic(handler: Box<dyn FnMut(&Unit) -> String>) -> Tree

Creates an action node with the specified handler function.

§Arguments
  • handler - The handler function that takes a Unit parameter which is the running AI agent and returns an action.
§Returns
  • A Leaf node that represents an action.
Source

pub fn accept() -> Tree

Creates a leaf node that represents accepting the current behavior tree.

Always get success result from this node.

§Returns
  • A Leaf node.
Source

pub fn reject() -> Tree

Creates a leaf node that represents rejecting the current behavior tree.

Always get failure result from this node.

§Returns
  • A Leaf node.
Source

pub fn behave(name: &str, root: &Tree) -> Tree

Creates a leaf node with the specified behavior tree as its root.

It is possible to include a Behavior Tree as a node in a Decision Tree by using the Behave() function. This allows the AI to use a combination of decision-making and behavior execution to achieve its goals.

§Arguments
  • name - The name of the behavior tree.
  • root - The root node of the behavior tree.
§Returns
  • A Leaf node.

Trait Implementations§

Source§

impl Clone for Tree

Source§

fn clone(&self) -> Tree

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Drop for Tree

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl IObject for Tree

Source§

fn raw(&self) -> i64

Source§

fn obj(&self) -> &dyn IObject

Source§

fn as_any(&self) -> &dyn Any

Source§

fn get_id(&self) -> i32

Auto Trait Implementations§

§

impl Freeze for Tree

§

impl RefUnwindSafe for Tree

§

impl Send for Tree

§

impl Sync for Tree

§

impl Unpin for Tree

§

impl UnwindSafe for Tree

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.