Guest User

Untitled

a guest
Jun 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. extern crate rand;
  2.  
  3. use rand::prelude::*;
  4.  
  5. #[derive(Debug, Copy, Clone)]
  6. enum CC{
  7. Spades,
  8. Hearts,
  9. Diamonds,
  10. Clubs,
  11. }
  12.  
  13. enum CV{
  14. Two=2,
  15. Three=3,
  16. Four=4,
  17. Five=5,
  18. Six=6,
  19. Seven=7,
  20. Eight=8,
  21. Nine=9,
  22. Ten=10,
  23. Jack=11,
  24. Queen=12,
  25. King=13,
  26. }
  27.  
  28. #[derive(Debug)]
  29. struct Card{
  30. color: CC,
  31. value: u8,
  32. }
  33.  
  34. struct Player{
  35. hand: Vec<Card>,
  36. }
  37.  
  38. fn main(){
  39. let colors = [CC::Spades, CC::Hearts, CC::Diamonds, CC::Clubs];
  40.  
  41. let deck: &mut Vec<Card> = &mut vec!();
  42. for color in &colors {
  43. for num in 2..13 {
  44. deck.push(
  45. Card{color:*color,value:num}
  46. );
  47. }
  48. }
  49.  
  50. fn draw_from(cards: &mut Vec<Card>) -> Option<Card>{
  51. let mut rng = thread_rng();
  52. let rand_index: usize = rng.gen_range(0, cards.len());
  53. if !cards.is_empty() {
  54. return Some(cards.remove(rand_index));
  55. }
  56. None
  57. }
  58.  
  59.  
  60. #[warn(dead_code)]
  61. let hand = [Card{color:CC::Spades,value:2},Card{color:CC::Spades,value:12}];
  62.  
  63. #[warn(dead_code)]
  64. let table = [
  65. Card{color:CC::Spades,value:2},
  66. Card{color:CC::Spades,value:12},
  67. Card{color:CC::Spades,value:12},
  68. Card{color:CC::Spades,value:2},
  69. Card{color:CC::Spades,value:12},
  70. ];
  71.  
  72.  
  73. println!("Catch 48:");
  74. while !deck.is_empty() {
  75. println!("\t{:?}", draw_from(deck));
  76. }
  77.  
  78. }
Add Comment
Please, Sign In to add comment