use crate::trick_taking::{OngoingTrick, TRICKS, Trick, TrickTakingGame};
#[derive(Debug, Clone, Copy)]
pub struct Hand<G>
where
G: TrickTakingGame,
{
tricks: [Trick<G>; TRICKS],
}
impl<G> Hand<G>
where
G: TrickTakingGame,
{
pub fn new(tricks: [Trick<G>; TRICKS]) -> Self {
Self { tricks }
}
pub fn tricks(&self) -> &[Trick<G>; TRICKS] {
&self.tricks
}
}
#[derive(Clone, Copy, Debug)]
pub struct OngoingHand<G>
where
G: TrickTakingGame,
{
current_trick: Option<OngoingTrick<G>>,
tricks: [Option<Trick<G>>; TRICKS],
}
impl<G> OngoingHand<G>
where
G: TrickTakingGame,
{
pub fn current_trick(&self) -> &Option<OngoingTrick<G>> {
&self.current_trick
}
pub fn tricks(&self) -> &[Option<Trick<G>>; TRICKS] {
&self.tricks
}
pub fn finish(self) -> Option<Hand<G>> {
let tricks: [Trick<G>; TRICKS] = self
.tricks
.into_iter()
.flatten()
.collect::<Vec<_>>()
.try_into()
.ok()?;
Some(Hand { tricks })
}
pub fn new() -> Self {
Self {
tricks: [const { None }; TRICKS],
current_trick: None,
}
}
pub fn add(&mut self, trick: Trick<G>, id: usize) {
self.tricks[id] = Some(trick);
}
pub fn current_trick_mut(&mut self) -> &mut Option<OngoingTrick<G>> {
&mut self.current_trick
}
pub fn set_current_trick(&mut self, trick: Option<OngoingTrick<G>>) {
self.current_trick = trick;
}
}
impl<G> Default for OngoingHand<G>
where
G: TrickTakingGame,
{
fn default() -> Self {
Self::new()
}
}