From: Geoffrey Allott Date: Mon, 12 Jun 2023 20:54:01 +0000 (+0100) Subject: anonymise card dealt to box, even for the dealer X-Git-Url: https://git.pointlesshacks.com/?a=commitdiff_plain;h=231bb6149e3cb8fe61d192a2f5a826739e3c067b;p=pokerwave.git anonymise card dealt to box, even for the dealer --- diff --git a/site/modules/chatroom.js b/site/modules/chatroom.js index 7911d01..1a75f03 100644 --- a/site/modules/chatroom.js +++ b/site/modules/chatroom.js @@ -137,6 +137,13 @@ export class Chatroom { this.chat.append(this.info_element(user_action.username, "Puts " + card_name(user_action.action.card) + " in the box")); } break; + case "DealBox": + if (user_action.action.card === null) { + this.chat.append(this.info_element(user_action.username, "Deals a card into the box")); + } else { + this.chat.append(this.info_element(user_action.username, "Deals " + card_name(user_action.action.card) + " into the box")); + } + break; case "WinHand": this.chat.append(this.info_element( user_action.username, diff --git a/site/modules/cribbage.js b/site/modules/cribbage.js index c6aa469..cfc6316 100644 --- a/site/modules/cribbage.js +++ b/site/modules/cribbage.js @@ -297,15 +297,17 @@ export class Cribbage extends GameWithChat { this.redraw_cards(); break; case "PutInBox": - if (!this.dealing) { - const removed = this.remove_card(user_action.username, user_action.action.card); - if (removed !== undefined) { - this.svg.removeChild(removed.image); - } + const removed = this.remove_card(user_action.username, user_action.action.card); + if (removed !== undefined) { + this.svg.removeChild(removed.image); } this.box.push({card: null, image: this.card_image(null, null)}); this.redraw_cards(); break; + case "DealBox": + this.box.push({card: null, image: this.card_image(null, null)}); + this.redraw_cards(); + break; case "CommunityCard": const turnup = { card: user_action.action.card, diff --git a/src/game/action.rs b/src/game/action.rs index 23c2eff..68da1c4 100644 --- a/src/game/action.rs +++ b/src/game/action.rs @@ -21,7 +21,12 @@ impl ValidatedUserAction { UserAction { timestamp: self.0.timestamp, username: self.0.username, - action: if username == self.0.username { self.0.action.clone() } else { self.0.action.anonymise() }, + action: match &self.0.action { + Action::ReceiveCard { .. } if username != self.0.username => Action::ReceiveCard { card: None }, + Action::PutInBox { .. } if username != self.0.username => Action::PutInBox { card: None }, + Action::DealBox { .. } => Action::DealBox { card: None }, + action => action.clone(), + } } } } @@ -47,6 +52,7 @@ pub enum Action { CutCard { card: Card }, PlayCard { card: Card }, PutInBox { card: Option }, + DealBox { card: Option }, Pass, ChooseTrumps { suit: Suit }, Fold, @@ -64,16 +70,6 @@ pub enum Action { KnockedOut, } -impl Action { - pub fn anonymise(&self) -> Self { - match self { - Action::ReceiveCard { .. } => Action::ReceiveCard { card: None }, - Action::PutInBox { .. } => Action::PutInBox { card: None }, - action => action.clone(), - } - } -} - #[derive(Debug, Copy, Clone, Serialize)] pub enum ActionError { NotAuthorised, diff --git a/src/game/cribbage/mod.rs b/src/game/cribbage/mod.rs index d813880..fc7dcee 100644 --- a/src/game/cribbage/mod.rs +++ b/src/game/cribbage/mod.rs @@ -290,7 +290,7 @@ impl Game for Cribbage { self.state = State::Choosing; Ok(()) } - (State::Dealing, Action::PutInBox { card: Some(card) }) => { + (State::Dealing, Action::DealBox { card: Some(card) }) => { self.deck.remove(&card); self.box_cards.insert(card); Ok(()) @@ -430,7 +430,7 @@ impl Game for Cribbage { } else if let Some(username) = self.dealer { if self.seats.players_len() == 3 && self.box_cards.is_empty() { if let Some(card) = rng.choose_from(self.deck) { - DealerAction::TakeAction(ValidatedUserAction(UserAction { timestamp, username, action: Action::PutInBox { card: Some(card) } })) + DealerAction::TakeAction(ValidatedUserAction(UserAction { timestamp, username, action: Action::DealBox { card: Some(card) } })) } else { error!("Expected to deal a card but none were left in deck"); DealerAction::Leave @@ -545,7 +545,7 @@ mod tests { let mut game = Cribbage::new(0, settings, seed); for action in actions { match action.action { - Action::Join { .. } | Action::PutInBox { .. } | Action::PlayCard { .. } | Action::Pass if game.state != State::Dealing => { + Action::Join { .. } | Action::PutInBox { .. } | Action::PlayCard { .. } | Action::Pass => { let validated = game.validate_action(action.clone()).unwrap(); assert_eq!(ValidatedUserAction(action), validated); game.take_action(validated).unwrap(); @@ -2295,7 +2295,7 @@ mod tests { {"timestamp":1686202533323,"username":"Peter","action":{"action":"ReceiveCard","card":{"rank":"Ten","suit":"Clubs"}}}, {"timestamp":1686202533323,"username":"Geoff","action":{"action":"ReceiveCard","card":{"rank":"Nine","suit":"Diamonds"}}}, {"timestamp":1686202533324,"username":"Aga","action":{"action":"ReceiveCard","card":{"rank":"Ace","suit":"Hearts"}}}, - {"timestamp":1686202533324,"username":"Aga","action":{"action":"PutInBox","card":{"rank":"Nine","suit":"Clubs"}}}, + {"timestamp":1686202533324,"username":"Aga","action":{"action":"DealBox","card":{"rank":"Nine","suit":"Clubs"}}}, {"timestamp":1686202533324,"username":"Aga","action":{"action":"EndDeal"}} ]"#;