pub struct SearchNode<A, Pl>where
A: GameAction,
Pl: Player,{
pub action: Option<A>,
pub children: Vec<SearchNode<A, Pl>>,
pub root_player: Pl,
pub state: NodeState,
pub visits: u32,
pub total_value: f32,
}Expand description
Represents the state of a node in the search tree.
Fields§
§action: Option<A>The action that this node represents. Only None for the root node.
children: Vec<SearchNode<A, Pl>>The children of this node.
root_player: PlThe player whose turn it was at the root node (initial game position).
state: NodeStateThe state of this node.
visits: u32The number of times this node has been visited.
total_value: f32The total value of this node as a result of rollouts.
Implementations§
Source§impl<A, Pl> SearchNode<A, Pl>where
A: GameAction,
Pl: Player,
impl<A, Pl> SearchNode<A, Pl>where
A: GameAction,
Pl: Player,
Sourcepub fn new(action: Option<A>, root_player: Pl) -> SearchNode<A, Pl>
pub fn new(action: Option<A>, root_player: Pl) -> SearchNode<A, Pl>
Constructs a new search node with the given action and root_player.
Sourcepub fn run_iteration<S, Po>(&mut self, game: &mut S, tree_policy: &Po) -> f32where
S: GameState<A, Pl>,
Po: TreePolicy<A, Pl>,
pub fn run_iteration<S, Po>(&mut self, game: &mut S, tree_policy: &Po) -> f32where
S: GameState<A, Pl>,
Po: TreePolicy<A, Pl>,
Runs a single iteration of the MCTS algorithm. Returns the reward for the player whose turn it was at the root node (initial game position).
Sourcepub fn expand<S>(&mut self, game: &S) -> Option<&mut SearchNode<A, Pl>>where
S: GameState<A, Pl>,
pub fn expand<S>(&mut self, game: &S) -> Option<&mut SearchNode<A, Pl>>where
S: GameState<A, Pl>,
Adds a child node to this leaf node if it is expandable, using a random legal action. If it is not, marks this node as a TerminalLeaf. If there is only one allowed action, this node is marked as a TerminalLeaf after expansion.