|
|
@@ -1,17 +1,14 @@
|
|
1
|
1
|
use card;
|
|
|
2
|
+use params;
|
|
2
|
3
|
use rand::{thread_rng, Rng};
|
|
3
|
4
|
use std::collections::BTreeSet;
|
|
4
|
5
|
|
|
5
|
|
-pub const DECK_SIZE: usize = 78;
|
|
6
|
|
-pub const NUMBER_OF_PLAYERS: usize = 4;
|
|
7
|
|
-pub const CARDS_PER_DISTRIBUTION: usize = 3;
|
|
8
|
|
-pub type Deck = [card::Card; DECK_SIZE];
|
|
9
|
|
-pub type Hand = BTreeSet<card::Card>;
|
|
10
|
|
-
|
|
|
6
|
+pub type Deck = [card::Card; params::DECK_SIZE];
|
|
|
7
|
+pub type Hand = (i32, BTreeSet<card::Card>);
|
|
11
|
8
|
|
|
12
|
9
|
// Creates a deck_size cards tarot deck, shuffled
|
|
13
|
10
|
pub fn new_deck() -> Deck {
|
|
14
|
|
- let mut deck: [card::Card; DECK_SIZE] = [card::Card::Fool; DECK_SIZE];
|
|
|
11
|
+ let mut deck: [card::Card; params::DECK_SIZE] = [card::Card::Fool; params::DECK_SIZE];
|
|
15
|
12
|
let mut counter = 0;
|
|
16
|
13
|
for suit in card::Suit::values() {
|
|
17
|
14
|
for symbol in card::Symbol::values() {
|
|
|
@@ -33,16 +30,18 @@ pub fn new_deck() -> Deck {
|
|
33
|
30
|
}
|
|
34
|
31
|
|
|
35
|
32
|
// Distributes the deck between the four players and the dog
|
|
36
|
|
-pub fn distribute_cards(deck: Deck) -> (Hand, [Hand; 4]) {
|
|
37
|
|
- let mut dog: Hand = BTreeSet::new();
|
|
38
|
|
- let mut hands: [Hand; NUMBER_OF_PLAYERS] =
|
|
39
|
|
- [BTreeSet::new(), BTreeSet::new(), BTreeSet::new(), BTreeSet::new()];
|
|
40
|
|
- for i in 0..(DECK_SIZE - 1) {
|
|
41
|
|
- if i <= 5 {
|
|
|
33
|
+pub fn distribute_cards(deck: Deck) -> (Hand, [Hand; params::NUMBER_OF_PLAYERS]) {
|
|
|
34
|
+ let (_, mut dog): Hand = (-1, BTreeSet::new());
|
|
|
35
|
+ let mut hands: [Hand; params::NUMBER_OF_PLAYERS] =
|
|
|
36
|
+ [(0, BTreeSet::new()), (1, BTreeSet::new()), (2, BTreeSet::new()), (3, BTreeSet::new())];
|
|
|
37
|
+ for i in 0..params::DECK_SIZE {
|
|
|
38
|
+ if i < params::DOG_SIZE {
|
|
42
|
39
|
dog.insert(deck[i]);
|
|
43
|
40
|
} else {
|
|
44
|
|
- hands[(i / CARDS_PER_DISTRIBUTION) % NUMBER_OF_PLAYERS].insert(deck[i]);
|
|
|
41
|
+ hands[(i / params::CARDS_PER_DISTRIBUTION) % params::NUMBER_OF_PLAYERS]
|
|
|
42
|
+ .1
|
|
|
43
|
+ .insert(deck[i]);
|
|
45
|
44
|
}
|
|
46
|
45
|
}
|
|
47
|
|
- (dog, hands)
|
|
|
46
|
+ ((-1, dog), hands)
|
|
48
|
47
|
}
|