impl Debug for CardSet {
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
- fmt.debug_struct("CardSet")
- .field("repr", &format_args!("{:#015x} /*{}*/", self.repr, itertools::join(*self, ", ")))
- .finish()
+ fmt.debug_struct("CardSet").field("repr", &format_args!("{:#015x} /*{}*/", self.repr, itertools::join(*self, ", "))).finish()
}
}
impl FromIterator<Card> for CardSet {
fn from_iter<T>(iter: T) -> Self
- where T: IntoIterator<Item=Card>
+ where
+ T: IntoIterator<Item = Card>,
{
let mut set = CardSet::new();
for card in iter {
mod score;
-use self::score::{PeggingScore, score_4_card_cribbage_hand, score_pegging, value};
+use self::score::{score_4_card_cribbage_hand, score_pegging, value, PeggingScore};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum State {
}
fn next_player_still_in(&self) -> Option<Username> {
- self.active.and_then(|player| self.seats.player_after_where(player, |player| self.players_still_in.contains(&player))
- .or_else(|| self.players_still_in.get(&player).copied()))
+ self.active.and_then(|player| {
+ self.seats.player_after_where(player, |player| self.players_still_in.contains(&player)).or_else(|| self.players_still_in.get(&player).copied())
+ })
}
fn last_pegging_score(&self) -> Option<(Username, PeggingScore)> {
self.state = State::ScoringPegging;
self.used_pegging_cards.append(&mut self.pegging_cards);
self.players_still_in = self.hands.iter().filter(|(_, cards)| !cards.is_empty()).map(|(&username, _)| username).collect();
- },
+ }
active => self.active = active,
}
Ok(())
}
State::ScoringTurnUp => {
if let Some(username) = self.dealer {
- DealerAction::TakeAction(ValidatedUserAction(UserAction { timestamp, username, action: Action::Score { points: 2, reason: "Two for his heels".to_string() } }))
+ DealerAction::TakeAction(ValidatedUserAction(UserAction {
+ timestamp,
+ username,
+ action: Action::Score { points: 2, reason: "Two for his heels".to_string() },
+ }))
} else {
error!("Expected to score the turn-up but there was no dealer");
DealerAction::Leave
if let Some(username) = self.winner() {
DealerAction::TakeAction(ValidatedUserAction(UserAction { timestamp, username, action: Action::WinGame }))
} else if let Some((username, score)) = self.last_pegging_score() {
- DealerAction::TakeAction(ValidatedUserAction(UserAction { timestamp, username, action: Action::Score { points: score.points() as u64, reason: format!("{}", score) } }))
+ DealerAction::TakeAction(ValidatedUserAction(UserAction {
+ timestamp,
+ username,
+ action: Action::Score { points: score.points() as u64, reason: format!("{}", score) },
+ }))
} else {
error!("Expected a pegging score");
DealerAction::Leave
DealerAction::TakeAction(ValidatedUserAction(UserAction { timestamp, username, action: Action::RevealCard { card } }))
} else if let (Some(hand), Some(turn_up)) = (self.four_card_hand(username), self.turn_up) {
let score = score_4_card_cribbage_hand(hand, turn_up, false);
- DealerAction::TakeAction(ValidatedUserAction(UserAction { timestamp, username, action: Action::Score { points: score.points() as u64, reason: format!("{}", score) } }))
+ DealerAction::TakeAction(ValidatedUserAction(UserAction {
+ timestamp,
+ username,
+ action: Action::Score { points: score.points() as u64, reason: format!("{}", score) },
+ }))
} else {
error!("Found no 4-card hand for scoring user");
DealerAction::Leave
DealerAction::TakeAction(ValidatedUserAction(UserAction { timestamp, username, action: Action::RevealCard { card } }))
} else if let (Some(hand), Some(turn_up)) = (self.four_card_box(), self.turn_up) {
let score = score_4_card_cribbage_hand(hand, turn_up, true);
- DealerAction::TakeAction(ValidatedUserAction(UserAction { timestamp, username, action: Action::Score { points: score.points() as u64, reason: format!("{}", score) } }))
+ DealerAction::TakeAction(ValidatedUserAction(UserAction {
+ timestamp,
+ username,
+ action: Action::Score { points: score.points() as u64, reason: format!("{}", score) },
+ }))
} else {
error!("Found no 4-card box for scoring user");
DealerAction::Leave
PeggingScore { fifteen: 0, thirty_one: 2, pair: 0, run: 6, go: false } => f.write_str("Thirty-one for two and a run of six is eight"),
PeggingScore { fifteen: 0, thirty_one: 2, pair: 6, run: 0, go: false } => f.write_str("Thirty-one for two and three-of-a-kind for six is eight"),
PeggingScore { fifteen: 0, thirty_one: 2, pair: 0, run: 7, go: false } => f.write_str("Thirty-one for two and a run of seven is nine"),
- PeggingScore { fifteen: 0, thirty_one: 2, pair: 12, run: 0, go: false } => f.write_str("Thirty-one for two and four-of-a-kind for twelve is fourteen"),
+ PeggingScore { fifteen: 0, thirty_one: 2, pair: 12, run: 0, go: false } => {
+ f.write_str("Thirty-one for two and four-of-a-kind for twelve is fourteen")
+ }
PeggingScore { fifteen: 0, thirty_one: 0, pair: 2, run: 0, go: false } => f.write_str("A pair"),
PeggingScore { fifteen: 0, thirty_one: 0, pair: 2, run: 0, go: true } => f.write_str("A pair and a go is three"),
PeggingScore { fifteen: 0, thirty_one: 0, pair: 0, run: 3, go: false } => f.write_str("A run of three"),
let score = score_4_card_cribbage_hand([ACE_OF_HEARTS, SEVEN_OF_SPADES, SEVEN_OF_CLUBS, SEVEN_OF_HEARTS], SEVEN_OF_DIAMONDS, false);
assert_eq!(24, score.points());
- assert_eq!("Fifteen two, fifteen four, fifteen six, fifteen eight, fifteen ten, fifteen twelve and four-of-a-kind for twelve is 24", format!("{}", score));
+ assert_eq!(
+ "Fifteen two, fifteen four, fifteen six, fifteen eight, fifteen ten, fifteen twelve and four-of-a-kind for twelve is 24",
+ format!("{}", score)
+ );
let score = score_4_card_cribbage_hand([FIVE_OF_CLUBS, FIVE_OF_DIAMONDS, FIVE_OF_HEARTS, JACK_OF_SPADES], TEN_OF_SPADES, false);
assert_eq!(21, score.points());
use getrandom::getrandom;
use rand::{CryptoRng, Error, Rng, RngCore, SeedableRng};
-use rand_chacha::{ChaCha8Rng, ChaCha20Rng};
+use rand_chacha::{ChaCha20Rng, ChaCha8Rng};
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "rng")]
}
pub fn choose_from<T, I>(&mut self, elements: I) -> Option<T>
- where
- T: Eq + Ord,
- I: IntoIterator<Item = T>,
+ where
+ T: Eq + Ord,
+ I: IntoIterator<Item = T>,
{
let mut vec = Vec::from_iter(elements);
let len = vec.len() as u32;
// anyway since advance() only moves forward by 4.
for _ in 0..4 {
i = rng.next_u32();
- if i <= zone { break; }
+ if i <= zone {
+ break;
+ }
}
i %= len
- },
+ }
WaveRng::ChaCha20(rng) => {
// Legacy implementation to match the `choose_stable`
// function on a sorted iterator. This calls rng.gen
}
}
}
- },
+ }
}
vec.select_nth_unstable(i as usize);
Some(vec.swap_remove(i as usize))