pub type Evaluation = i16;
pub const BEST_EVAL: Evaluation = i16::MAX;
pub const WORST_EVAL: Evaluation = -BEST_EVAL;
pub trait Evaluator {
type G: Game;
fn evaluate(&self, s: &<Self::G as Game>::S) -> Evaluation;
fn generate_noisy_moves(
&self, _state: &<Self::G as Game>::S, _moves: &mut Vec<<Self::G as Game>::M>,
) {
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Winner {
PlayerJustMoved,
Draw,
PlayerToMove,
}
impl Winner {
pub fn evaluate(&self) -> Evaluation {
match *self {
Winner::PlayerJustMoved => WORST_EVAL,
Winner::PlayerToMove => BEST_EVAL,
Winner::Draw => 0,
}
}
}
pub trait Game: Sized {
type S;
type M: Copy;
fn generate_moves(state: &Self::S, moves: &mut Vec<Self::M>) -> Option<Winner>;
fn apply(state: &mut Self::S, m: Self::M) -> Option<Self::S>;
fn undo(_state: &mut Self::S, _m: Self::M) {}
fn get_winner(state: &Self::S) -> Option<Winner>;
fn zobrist_hash(_state: &Self::S) -> u64 {
unimplemented!("game has not implemented zobrist hash");
}
fn null_move(_state: &Self::S) -> Option<Self::M> {
None
}
fn notation(_state: &Self::S, _move: Self::M) -> Option<String> {
None
}
fn table_index(_: Self::M) -> u16 {
0
}
fn max_table_index() -> u16 {
0
}
}
pub trait Strategy<G: Game> {
fn choose_move(&mut self, state: &G::S) -> Option<G::M>;
fn set_timeout(&mut self, _timeout: std::time::Duration) {}
fn set_max_depth(&mut self, _depth: u8) {}
fn set_depth_or_timeout(&mut self, _depth: u8, _timeout: std::time::Duration) {}
fn principal_variation(&self) -> Vec<G::M> {
Vec::new()
}
}