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§
- impl_
task_ boxed_ methods - Task implementors can use this macro to implement the
box_clone
,box_hash
andbox_eq
functions.
Structs§
- Active
Task - A task associated to an agent and that is being processed by the planner.
- AgentId
- The identifier of an agent, essentially a u32.
- Default
Policy Estimator - MCTS default policy using simulation-based rollout.
- Edge
Inner - The data associated with an edge.
- Edges
- The outgoing edges from a node, possibly partially expanded.
- Idle
Task - An idle task of duration 1 that is used by the planner when the task of an agent is not known.
- MCTS
- The state of a running planner instance.
- MCTS
Configuration - The configuration of an MCTS instance.
- Node
Inner - The data associated to a node that form its key.
- Planning
Task - A task to represent planning in the planning tree, if these need to be represented.
- State
Diff Ref - A joint reference to an initial state and a difference to this state.
- State
Diff RefMut - A joint reference to an initial state and a difference to this state, where the difference is mutable.
Traits§
- Behavior
- A possibly-recursive set of possible tasks.
- Domain
- A domain on which the MCTS planner can plan.
- Domain
With Planning Task - Domains who want to use planning tasks must implement this.
- State
Value Estimator - An estimator of state-value function.
- Task
- A task that modifies the state.
Functions§
- debug_
name_ to_ filename_ safe - Transforms the debug string of a task to a string that can safely be used for filenames.
Type Aliases§
- Active
Tasks - A set of active tasks.
- Agent
Value - The “current” value an agent has in a given state.
- Early
Stop Condition - A functor that returns whether the planner must do an early stop.
- Edge
- Strong atomic reference counted edge.
- Node
- Strong atomic reference counted node.
- Task
Duration - The duration of a task, in ticks.
- Weak
Node - Weak atomic reference counted node.