Skip to main content

TreePolicy

Trait TreePolicy 

Source
pub trait TreePolicy<Spec: MCTS<TreePolicy = Self>>: Sync + Sized {
    type MoveEvaluation: Sync + Send + Default;
    type ThreadLocalData: Default;

    // Required method
    fn choose_child<'a, MoveIter>(
        &self,
        moves: MoveIter,
        handle: SearchHandle<'_, Spec>,
    ) -> &'a MoveInfo<Spec>
       where MoveIter: Iterator<Item = &'a MoveInfo<Spec>> + Clone;

    // Provided methods
    fn validate_evaluations(&self, _evalns: &[Self::MoveEvaluation]) { ... }
    fn seed_thread_data(&self, _tld: &mut Self::ThreadLocalData, _seed: u64) { ... }
    fn compare_move_evaluations(
        &self,
        _a: &Self::MoveEvaluation,
        _b: &Self::MoveEvaluation,
    ) -> Ordering { ... }
    fn apply_dirichlet_noise(
        &self,
        _moves: &mut [MoveInfo<Spec>],
        _epsilon: f64,
        _alpha: f64,
        _rng: &mut Rng64,
    ) { ... }
}
Expand description

Selects which child to explore during MCTS tree traversal.

Two built-in policies are provided:

  • UCTPolicy — classic UCB1 (Upper Confidence Bound). Move evaluations are ().
  • AlphaGoPolicy — PUCT with prior probabilities. Move evaluations are f64 priors.

Required Associated Types§

Source

type MoveEvaluation: Sync + Send + Default

Per-move evaluation produced by the evaluator (e.g., () for UCT, f64 prior for PUCT).

Source

type ThreadLocalData: Default

Thread-local data for the policy (e.g., an RNG for tie-breaking).

Required Methods§

Source

fn choose_child<'a, MoveIter>( &self, moves: MoveIter, handle: SearchHandle<'_, Spec>, ) -> &'a MoveInfo<Spec>
where MoveIter: Iterator<Item = &'a MoveInfo<Spec>> + Clone,

Select the most promising child to explore during a playout.

Provided Methods§

Source

fn validate_evaluations(&self, _evalns: &[Self::MoveEvaluation])

Validate move evaluations after node creation (e.g., check priors sum to 1).

Source

fn seed_thread_data(&self, _tld: &mut Self::ThreadLocalData, _seed: u64)

Seed the thread-local data for deterministic search. Called when the MCTS config provides an rng_seed().

Source

fn compare_move_evaluations( &self, _a: &Self::MoveEvaluation, _b: &Self::MoveEvaluation, ) -> Ordering

Compare two move evaluations for ordering during progressive widening. Higher-priority moves should sort first (return Greater for higher priority a). Default: Equal (no reordering).

Source

fn apply_dirichlet_noise( &self, _moves: &mut [MoveInfo<Spec>], _epsilon: f64, _alpha: f64, _rng: &mut Rng64, )

Apply Dirichlet noise to root move evaluations for self-play exploration. Default: no-op (appropriate when MoveEvaluation is not numeric).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§