use std::fmt::Debug;
use ego_tree::{NodeId, Tree};
use crate::aliases::{LazyMctsNode, LazyMctsTree, Num};
use crate::mcts_node::MctsNode;
use crate::Nat;
pub trait GameTrait: Clone {
type Player: Debug + Clone + Eq;
type Move: Debug + Clone;
fn legals_moves(&self) -> Vec<Self::Move>;
fn player_turn(&self) -> Self::Player;
fn hash(&self) -> u64;
fn is_final(&self) -> bool;
fn do_move(&mut self, m: &Self::Move);
fn get_winner(&self) -> Self::Player;
}
pub trait Evaluator<State: GameTrait, Reward: Clone, AdditionalInfo: Clone + Default> {
type Args;
type EvalResult: Clone;
fn eval_child(
child: &LazyMctsNode<State, Reward, AdditionalInfo>,
turn: &State::Player,
parent_visits: Nat,
args: &Self::Args,
) -> Num;
fn evaluate_leaf(child: State, turn: &State::Player) -> Self::EvalResult;
}
pub trait Playout<State> {
type Args;
fn playout(state: State, args: Self::Args) -> State;
}
pub trait LazyTreePolicy<
State: GameTrait,
EV: Evaluator<State, Reward, A>,
A: Clone + Default,
Reward: Clone,
>
{
fn tree_policy(
tree: &mut LazyMctsTree<State, Reward, A>,
root_state: State,
evaluator_args: &EV::Args,
) -> (NodeId, State);
fn update_state(mut root_state: State, historic: &[State::Move]) -> State {
for x in historic {
root_state.do_move(x)
}
return root_state;
}
fn best_child(
tree: &LazyMctsTree<State, Reward, A>,
turn: &State::Player,
parent_id: NodeId,
evaluator_args: &EV::Args,
) -> NodeId;
}
pub trait BackPropPolicy<
State: Clone,
Move: Clone,
Reward: Clone,
AdditionalInfo: Clone + Default,
EvalResult = Reward,
>
{
fn backprop(
tree: &mut Tree<MctsNode<State, Move, Reward, AdditionalInfo>>,
leaf: NodeId,
playout_result: EvalResult,
);
}