use crate::{Moment, Turn, WorkCount};
use super::HostAction;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum HostPhase {
Running,
Stopped,
Terminated,
Failed,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct HostSnapshot {
phase: HostPhase,
turns: u64,
work: WorkCount,
last_moment: Option<Moment>,
last_turn: Option<Turn>,
last_action: Option<HostAction>,
}
impl HostSnapshot {
pub(super) const fn new() -> Self {
Self {
phase: HostPhase::Running,
turns: 0,
work: WorkCount::ZERO,
last_moment: None,
last_turn: None,
last_action: None,
}
}
pub const fn phase(self) -> HostPhase {
self.phase
}
pub const fn turns(self) -> u64 {
self.turns
}
pub const fn work(self) -> WorkCount {
self.work
}
pub const fn last_moment(self) -> Option<Moment> {
self.last_moment
}
pub const fn last_turn(self) -> Option<Turn> {
self.last_turn
}
pub const fn last_action(self) -> Option<HostAction> {
self.last_action
}
pub(super) fn observe(&mut self, moment: Moment) {
self.last_moment = Some(moment);
}
pub(super) fn record(&mut self, turn: Turn, action: HostAction) {
self.turns = self.turns.saturating_add(1);
self.work = self.work.saturating_add(turn.work());
self.last_turn = Some(turn);
self.last_action = Some(action);
}
pub(super) fn stop(&mut self) {
self.phase = HostPhase::Stopped;
}
#[cfg(feature = "std")]
pub(super) fn terminate(&mut self) {
self.phase = HostPhase::Terminated;
}
pub(super) fn fail(&mut self) {
self.phase = HostPhase::Failed;
}
}