run cargo fmt
authorGeoffrey Allott <geoffrey@allott.email>
Wed, 7 Jun 2023 23:23:53 +0000 (00:23 +0100)
committerGeoffrey Allott <geoffrey@allott.email>
Wed, 7 Jun 2023 23:23:53 +0000 (00:23 +0100)
src/card.rs
src/game/cribbage/mod.rs
src/game/cribbage/score.rs
src/rng.rs

index 042b99fbe142eb91deb6b6c10254896de44bb02f..e38c9289836776d07f629985dbb982bd635d1150 100644 (file)
@@ -134,9 +134,7 @@ pub struct CardSet {
 
 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()
     }
 }
 
@@ -220,7 +218,8 @@ impl Iterator for CardSetIntoIter {
 
 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 {
index 5f1ff8a519d042716abc9b8d5195cba56d566b60..1dcd1ced134210fee9c69ab039b2cb27cf6cd491 100644 (file)
@@ -10,7 +10,7 @@ use super::{Action, ActionError, DealerAction, Game, StartCondition, UserAction,
 
 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 {
@@ -113,8 +113,9 @@ impl Cribbage {
     }
 
     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)> {
@@ -341,7 +342,7 @@ impl Game for Cribbage {
                         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(())
@@ -453,7 +454,11 @@ impl Game for Cribbage {
             }
             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
@@ -464,7 +469,11 @@ impl Game for Cribbage {
                 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
@@ -478,7 +487,11 @@ impl Game for Cribbage {
                         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
@@ -498,7 +511,11 @@ impl Game for Cribbage {
                         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
index 98657c848bb3d9da18309749a8458711015648f5..515122eeb6601dc162446a31c1efcb8aea34624e 100644 (file)
@@ -148,7 +148,9 @@ impl Display for PeggingScore {
             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"),
@@ -290,7 +292,10 @@ mod test {
 
         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());
index 5f1a604d3ed725843cfe1844db106f0f22abe971..e52c306e916ec68f96ce7e09c474b086b8e9a939 100644 (file)
@@ -2,7 +2,7 @@ use std::cmp::{Eq, Ord};
 
 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")]
@@ -54,9 +54,9 @@ impl WaveRng {
     }
 
     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;
@@ -75,10 +75,12 @@ impl WaveRng {
                 // 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
@@ -113,7 +115,7 @@ impl WaveRng {
                         }
                     }
                 }
-            },
+            }
         }
         vec.select_nth_unstable(i as usize);
         Some(vec.swap_remove(i as usize))