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,
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,
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(),
+ }
}
}
}
CutCard { card: Card },
PlayCard { card: Card },
PutInBox { card: Option<Card> },
+ DealBox { card: Option<Card> },
Pass,
ChooseTrumps { suit: Suit },
Fold,
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,
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(())
} 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
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();
{"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"}}
]"#;