Last active
August 29, 2015 14:09
-
-
Save dradtke/627801ca5da80aa5ab4c to your computer and use it in GitHub Desktop.
Rustic deck of cards.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::rand::{task_rng, Rng}; | |
| #[allow(dead_code)] | |
| enum Value { | |
| Ace, | |
| Two, | |
| Three, | |
| Four, | |
| Five, | |
| Six, | |
| Seven, | |
| Eight, | |
| Nine, | |
| Ten, | |
| Jack, | |
| Queen, | |
| King, | |
| } | |
| #[allow(dead_code)] | |
| enum Suit { | |
| Clubs, | |
| Diamonds, | |
| Hearts, | |
| Spades, | |
| } | |
| type Card = (Value, Suit); | |
| type Deck = Vec<Card>; | |
| fn new_deck() -> Deck { | |
| vec![ | |
| (Ace, Clubs), | |
| (Two, Clubs), | |
| // everything else here | |
| ] | |
| } | |
| fn shuffle_deck(deck: &mut Deck) { | |
| task_rng().shuffle(deck.as_mut_slice()); | |
| } | |
| fn main() { | |
| let mut deck = new_deck(); | |
| shuffle_deck(&mut deck); | |
| // use the deck here | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment