use crate::{GameDelta, Point};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Commit {
Turn,
Transient,
}
#[derive(Clone, Debug, PartialEq)]
pub(super) struct AppliedDelta {
pub delta: GameDelta,
pub commit: Commit,
pub removed_forced_eyes: Vec<Point>,
}
#[derive(Clone, Debug, Default)]
pub(super) struct History {
entries: Vec<AppliedDelta>,
}
impl History {
pub fn push(&mut self, entry: AppliedDelta) {
self.entries.push(entry);
}
pub fn pop(&mut self) -> Option<AppliedDelta> {
self.entries.pop()
}
pub fn last_committed(&self) -> Option<&GameDelta> {
self.entries
.iter()
.rev()
.find(|entry| entry.commit == Commit::Turn)
.map(|entry| &entry.delta)
}
pub fn committed(&self) -> impl DoubleEndedIterator<Item = &GameDelta> {
self.entries
.iter()
.filter(|entry| entry.commit == Commit::Turn)
.map(|entry| &entry.delta)
}
pub fn committed_count(&self) -> usize {
self.committed().count()
}
pub fn iter(&self) -> impl Iterator<Item = &AppliedDelta> {
self.entries.iter()
}
}