use super::action::*;
use crate::game::{
error::{ActionError, GameError},
score::{RoundScore, VariantPlayerScore},
state::{GameState, VariantState},
};
pub trait GameRules
where
Self: Sized + PartialEq,
{
type VariantState: VariantState<Self::VariantScore, Self>;
type VariantScore: VariantPlayerScore;
fn execute_action(
&self,
state: &mut GameState<Self::VariantScore, Self>,
action: GameAction,
) -> Result<(), ActionError> {
state.validate_action(&action)?;
match action {
GameAction::DrawDeck(action) => self.handle_draw_deck(state, action),
GameAction::DrawDiscardPile(action) => self.handle_draw_discard_pile(state, action),
GameAction::LayOff(action) => self.handle_lay_off(state, action),
GameAction::FormMeld(action) => self.handle_form_meld(state, action),
GameAction::FormMelds(action) => self.handle_form_melds(state, action),
GameAction::Discard(action) => self.handle_discard(state, action),
}
}
fn handle_draw_deck(
&self,
state: &mut GameState<Self::VariantScore, Self>,
action: DrawDeckAction,
) -> Result<(), ActionError>;
fn handle_draw_discard_pile(
&self,
state: &mut GameState<Self::VariantScore, Self>,
action: DrawDiscardPileAction,
) -> Result<(), ActionError>;
fn handle_lay_off(
&self,
state: &mut GameState<Self::VariantScore, Self>,
action: LayOffAction,
) -> Result<(), ActionError>;
fn handle_form_meld(
&self,
state: &mut GameState<Self::VariantScore, Self>,
action: FormMeldAction,
) -> Result<(), ActionError>;
fn handle_form_melds(
&self,
state: &mut GameState<Self::VariantScore, Self>,
action: FormMeldsAction,
) -> Result<(), ActionError>;
fn handle_discard(
&self,
state: &mut GameState<Self::VariantScore, Self>,
action: DiscardAction,
) -> Result<(), ActionError>;
fn calculate_round_score(
&self,
state: &GameState<Self::VariantScore, Self>,
) -> Result<RoundScore<Self::VariantScore>, GameError>;
}