Crate npc_engine_core
source · [−]Expand description
This is the core of the NPC engine, containing the MCTS algorithm implementation and related abstractions.
We provide several examples as introductions on how to use the planner. A good place to start is tic-tac-toe.
The core of the planner is the MCTS struct, which holds the state of the planner. It has two constructors, a simplified one, new, and a complete one, new_with_tasks. Once constructed, the run method performs the search and returns the best task. After a search, the resulting tree can be inspected, starting from the root node.
The MCTS struct is generic over a Domain, which you have to implement to describe your own planning domain. You need to implement at least these three methods:
- list_behaviors returns the possible actions employing a hierarchical Behavior abstraction.
- get_current_value returns the instantaneous (not discounted) value of an agent in a given state.
- update_visible_agents lists all agents visible from a given agent in a given state.
The graphviz
feature enables to output the search tree in the Graphviz’s dot format using the plot_mcts_tree function.
Additional features and utilites such as execution loops are available in the npc-engine-utils
crate.
You might want to use them in your project as they make the planner significantly simpler to use.
Most examples use them.
Macros
Task implementors can use this macro to implement the box_clone
, box_hash
and box_eq
functions.
Structs
A task associated to an agent and that is being processed by the planner.
The identifier of an agent, essentially a u32.
MCTS default policy using simulation-based rollout.
The data associated with an edge.
The outgoing edges from a node, possibly partially expanded.
An idle task of duration 1 that is used by the planner when the task of an agent is not known.
The state of a running planner instance.
The configuration of an MCTS instance.
The data associated to a node that form its key.
A task to represent planning in the planning tree, if these need to be represented.
A joint reference to an initial state and a difference to this state.
A joint reference to an initial state and a difference to this state, where the difference is mutable.
Traits
A possibly-recursive set of possible tasks.
A domain on which the MCTS planner can plan.
Domains who want to use planning tasks must implement this.
An estimator of state-value function.
A task that modifies the state.
Functions
Transforms the debug string of a task to a string that can safely be used for filenames.
Type Definitions
A set of active tasks.
The “current” value an agent has in a given state.
A functor that returns whether the planner must do an early stop.
Strong atomic reference counted edge.
Strong atomic reference counted node.
The duration of a task, in ticks.
Weak atomic reference counted node.