SearchNode

Struct SearchNode 

Source
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: Pl

The player whose turn it was at the root node (initial game position).

§state: NodeState

The state of this node.

§visits: u32

The number of times this node has been visited.

§total_value: f32

The total value of this node as a result of rollouts.

Implementations§

Source§

impl<A, Pl> SearchNode<A, Pl>
where A: GameAction, Pl: Player,

Source

pub fn new(action: Option<A>, root_player: Pl) -> SearchNode<A, Pl>

Constructs a new search node with the given action and root_player.

Source

pub fn run_iteration<S, Po>(&mut self, game: &mut S, tree_policy: &Po) -> f32
where 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).

Source

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.

Source

pub fn get_node_count(&self) -> u32

Trait Implementations§

Source§

impl<A, Pl> Display for SearchNode<A, Pl>
where A: GameAction, Pl: Player,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A, Pl> Freeze for SearchNode<A, Pl>
where Pl: Freeze, A: Freeze,

§

impl<A, Pl> RefUnwindSafe for SearchNode<A, Pl>

§

impl<A, Pl> Send for SearchNode<A, Pl>
where Pl: Send, A: Send,

§

impl<A, Pl> Sync for SearchNode<A, Pl>
where Pl: Sync, A: Sync,

§

impl<A, Pl> Unpin for SearchNode<A, Pl>
where Pl: Unpin, A: Unpin,

§

impl<A, Pl> UnwindSafe for SearchNode<A, Pl>
where Pl: UnwindSafe, A: UnwindSafe,

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.