use super::{GameState, action::Action};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum HistorianError {
#[error("Unable to record action")]
UnableToRecordAction,
#[error("IO Error: {0}")]
IOError(#[from] std::io::Error),
#[error("Borrow Mut Error: {0}")]
BorrowMutError(#[from] std::cell::BorrowMutError),
#[error("Borrow Error: {0}")]
BorrowError(#[from] std::cell::BorrowError),
#[cfg(any(test, feature = "serde"))]
#[error("JSON Error: {0}")]
JSONError(#[from] serde_json::Error),
#[error("Unexpected CFR Node: {0}")]
CFRUnexpectedNode(String),
#[error("Expected Node not found in tree")]
CFRNodeNotFound,
}
pub trait Historian {
fn record_action(
&mut self,
id: u128,
game_state: &GameState,
action: Action,
) -> Result<(), HistorianError>;
}
pub trait HistorianGenerator {
fn generate(&self, game_state: &GameState) -> Box<dyn Historian>;
}
pub trait CloneHistorian: Historian {
fn clone_box(&self) -> Box<dyn Historian>;
}
impl<T> CloneHistorian for T
where
T: 'static + Historian + Clone,
{
fn clone_box(&self) -> Box<dyn Historian> {
Box::new(self.clone())
}
}
pub struct CloneHistorianGenerator<T> {
historian: T,
}
impl<T> CloneHistorianGenerator<T>
where
T: CloneHistorian,
{
pub fn new(historian: T) -> Self {
CloneHistorianGenerator { historian }
}
}
impl<T> HistorianGenerator for CloneHistorianGenerator<T>
where
T: CloneHistorian,
{
fn generate(&self, _game_state: &GameState) -> Box<dyn Historian> {
self.historian.clone_box()
}
}
mod failing;
mod fn_historian;
mod null;
mod stats_tracking;
mod vec;
#[cfg(any(test, feature = "serde"))]
mod directory_historian;
pub use failing::FailingHistorian;
pub use fn_historian::FnHistorian;
pub use null::NullHistorian;
pub use vec::HistoryRecord;
pub use vec::VecHistorian;
#[cfg(any(test, feature = "serde"))]
pub use directory_historian::DirectoryHistorian;
pub use stats_tracking::StatsTrackingHistorian;