summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-12-25 09:33:48 -0500
committerKjetil Orbekk <kj@orbekk.com>2022-12-25 09:34:03 -0500
commitf081bf262e648f86a4e42aa848ff9e64d878cefd (patch)
treeb5006fca86dbcbf9f5fbabcebde410f44abb1d2c
parent0f2910c70172992fdb3a385816f3df3f4336ffc4 (diff)
Get rid of TurnInPlayResult and use MoveResult
-rw-r--r--protocol/src/bridge_engine.rs24
1 files 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<Trick>),
-}
-
impl DealInPlay {
pub fn new(
leader: Player,
@@ -213,7 +207,7 @@ impl DealInPlay {
pub fn play(
mut self: Self,
card: Card,
- ) -> Result<DealInPlayResult, anyhow::Error> {
+ ) -> Result<MoveResult<DealInPlay, Vec<Trick>>, 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<PlayStateResult, anyhow::Error> {
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, Vec<Trick>>) -> DealInPlay {
match result {
- DealInPlayResult::InProgress(r) => r,
- DealInPlayResult::PlayFinished(_) => {
+ MoveResult::Current(r) => r,
+ MoveResult::Next(_) => {
panic!("expected PlayingDealResult::InProgress(): {:?}", result)
}
}