diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-12-23 16:16:35 -0500 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-12-23 16:18:41 -0500 |
commit | 45ce66a29b3d1c49ef8e86b125701e89d58e8a4a (patch) | |
tree | 14d67dfef5c2d5e1aa7e4100526973cbd0ba4c2b /server/src/play.rs | |
parent | 82c447fbfe12ee76dbbdaa36b0de1343d3a91795 (diff) |
Generalize table state to include the result of play
Diffstat (limited to 'server/src/play.rs')
-rw-r--r-- | server/src/play.rs | 40 |
1 files changed, 9 insertions, 31 deletions
diff --git a/server/src/play.rs b/server/src/play.rs index ffb7407..e0d4733 100644 --- a/server/src/play.rs +++ b/server/src/play.rs @@ -3,10 +3,9 @@ use protocol::{ bot::{BiddingBot, PlayingBot}, bridge_engine::{ Bid, BiddingStatePlayerView, Deal, GameResult, GameState, - PlayStatePlayerView, Player, + PlayStatePlayerView, Player, TableState, }, card::Card, - play_result::MoveResult, simple_bots::{AlwaysPassBiddingBot, RandomPlayingBot}, }; use rand::random; @@ -125,35 +124,7 @@ where { journal: J, settings: TableSettings, - state: TableState, -} - -#[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)] -pub enum TableState { - Unknown, - Game(GameState), - Result(GameResult), -} - -impl Default for TableState { - fn default() -> Self { - TableState::Unknown - } -} - -impl Into<TableState> for MoveResult<GameState, GameResult> { - fn into(self) -> TableState { - match self { - MoveResult::Stay(game) => TableState::Game(game), - MoveResult::Go(result) => TableState::Result(result), - } - } -} - -impl Into<TableState> for GameState { - fn into(self) -> TableState { - TableState::Game(self) - } + pub state: TableState, } impl<J: Journal<TableUpdate>> Table<J> { @@ -167,6 +138,13 @@ impl<J: Journal<TableUpdate>> Table<J> { Ok(table) } + pub fn game_in_progress(&self) -> bool { + match &self.state { + TableState::Game(_) => true, + _ => false, + } + } + pub fn game(&self) -> Result<&GameState, BridgeError> { match &self.state { TableState::Game(g) => Ok(g), |