From f081bf262e648f86a4e42aa848ff9e64d878cefd Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sun, 25 Dec 2022 09:33:48 -0500 Subject: Get rid of TurnInPlayResult and use MoveResult --- protocol/src/bridge_engine.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/protocol/src/bridge_engine.rs b/protocol/src/bridge_engine.rs index 0acdca9..37687b8 100644 --- a/protocol/src/bridge_engine.rs +++ b/protocol/src/bridge_engine.rs @@ -169,12 +169,6 @@ pub struct DealInPlay { in_progress: TurnInPlay, } -#[derive(Debug)] -pub enum DealInPlayResult { - InProgress(DealInPlay), - PlayFinished(Vec), -} - impl DealInPlay { pub fn new( leader: Player, @@ -213,7 +207,7 @@ impl DealInPlay { pub fn play( mut self: Self, card: Card, - ) -> Result { + ) -> Result>, anyhow::Error> { let player = self.current_player(); let player_cards = player.get_cards_mut(&mut self.deal); @@ -238,7 +232,7 @@ impl DealInPlay { Ok(match self.in_progress.play(card) { MoveResult::Current(turn) => { - DealInPlayResult::InProgress(Self { + MoveResult::Current(Self { in_progress: turn, ..self }) @@ -249,9 +243,9 @@ impl DealInPlay { tricks.push(trick); if player_cards.is_empty() { - DealInPlayResult::PlayFinished(tricks) + MoveResult::Next(tricks) } else { - DealInPlayResult::InProgress(Self { + MoveResult::Current(Self { trump_suit: self.trump_suit, in_progress: TurnInPlay::new(trick_winner), tricks_played: tricks, @@ -681,13 +675,13 @@ impl PlayState { pub fn play(self, card: Card) -> Result { Ok(match self.playing_deal.play(card)? { - DealInPlayResult::InProgress(playing_deal) => { + MoveResult::Current(playing_deal) => { PlayStateResult::InProgress(Self { playing_deal, ..self }) } - DealInPlayResult::PlayFinished(_) => { + MoveResult::Next(_) => { PlayStateResult::PlayFinished(PlayResult) } }) @@ -1313,10 +1307,10 @@ mod tests { assert_eq!(player_state.current_player(), play_state.current_player()); } - fn as_playing_hand(result: DealInPlayResult) -> DealInPlay { + fn as_playing_hand(result: MoveResult>) -> DealInPlay { match result { - DealInPlayResult::InProgress(r) => r, - DealInPlayResult::PlayFinished(_) => { + MoveResult::Current(r) => r, + MoveResult::Next(_) => { panic!("expected PlayingDealResult::InProgress(): {:?}", result) } } -- cgit v1.2.3