Skip to main content

server/domain/
commands.rs

1use serde::{Deserialize, Serialize};
2use strum::AsRefStr;
3
4use crate::domain::{Card, GameId, Player, UserId};
5
6/// Commands that drive the game state machine.
7///
8/// Each variant represents an action a player can take.
9#[derive(Debug, Serialize, Deserialize, AsRefStr)]
10#[strum(serialize_all = "snake_case")]
11#[serde(tag = "type", content = "data")]
12pub enum GameCommand {
13    /// User wants to create a new game and become its host. The game will require a guest to join in order to continue.
14    HostGame {
15        /// User hosting the game.
16        user_id: UserId,
17
18        /// The new game identity.
19        game_id: GameId,
20    },
21
22    /// User wants to join the game has a guest.
23    JoinGame {
24        /// User hosting the game.
25        user_id: UserId,
26    },
27
28    /// Client wants to start a single-player game against the computer.
29    PlayComputer {
30        /// User creating the game.
31        user_id: UserId,
32
33        /// The new game identity.
34        game_id: GameId,
35    },
36
37    /// Player cuts the deck to determine who deals first.
38    CutForDeal {
39        /// The player identity (essentially host or guest)
40        player: Player,
41    },
42
43    /// Player signals they are ready for the game to start.
44    /// This is a `Pending` acknowledgment on the `CutForDeal` cuts.
45    StartGame {
46        /// The player identity (essentially host or guest)
47        player: Player,
48    },
49
50    /// Player discards two cards to the crib.
51    DiscardCards {
52        /// The player identity (essentially host or guest)
53        player: Player,
54
55        /// The cards being discarded.
56        cards: Vec<Card>,
57    },
58
59    /// Player plays a card during the `Playing` (or Pegging) phase.
60    PlayCard {
61        /// The player identity (essentially host or guest)
62        player: Player,
63
64        /// The card to be played.
65        card: Card,
66    },
67
68    /// Player declares go during the `Playing` (or Pegging) phase.
69    Go {
70        /// The player identity (essentially host or guest)
71        player: Player,
72    },
73
74    /// Player requests scoring of the non-dealer's hand.
75    /// This is a `Pending` acknowledgment at the end of the `Playing` phase.
76    ScorePone {
77        /// The player identity (essentially host or guest)
78        player: Player,
79    },
80
81    /// Player requests scoring of the dealer's hand.
82    /// This is a `Pending` acknowledgment at the end of the `ScoringPone` phase.
83    ScoreDealer {
84        /// The player identity (essentially host or guest)
85        player: Player,
86    },
87
88    /// Player requests scoring of the dealer's crib.
89    /// This is a `Pending` acknowledgment at the end of the `ScoringDealer` phase.
90    ScoreCrib {
91        /// The player identity (essentially host or guest)
92        player: Player,
93    },
94
95    /// Player requests that the next `Discarding` round should start.
96    /// This is a `Pending` acknowledgment at the end of the `ScoringCrib` phase.
97    StartNextRound {
98        /// The player identity (essentially host or guest)
99        player: Player,
100    },
101}