-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeal.cc
39 lines (32 loc) · 1.14 KB
/
deal.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "random.h"
#include "singleton.h"
#include <cstdlib>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
lace::random & rng = lace::singleton<lace::random>::instance();
template<typename T>
T & fisher_yates(T & a) {
for (unsigned i = a.size() - 1 ; i > 0 ; --i)
std::swap(a[i], a[rng.roll(i)]);
return a;
}
int
main(int argc, char* argv[]) {
std::vector<std::string> cards = {
"♠A", "♠K", "♠Q", "♠J", "♠T", "♠9", "♠8", "♠7", "♠6", "♠5", "♠4", "♠3", "♠2",
"♥A", "♥K", "♥Q", "♥J", "♥T", "♥9", "♥8", "♥7", "♥6", "♥5", "♥4", "♥3", "♥2",
"♦A", "♦K", "♦Q", "♦J", "♦T", "♦9", "♦8", "♦7", "♦6", "♦5", "♦4", "♦3", "♦2",
"♣A", "♣K", "♣Q", "♣J", "♣T", "♣9", "♣8", "♣7", "♣6", "♣5", "♣4", "♣3", "♣2",
};
fisher_yates(cards);
for (auto i = cards.begin() ; i < cards.end() ; i += 13) {
std::sort(i, i + 13);
for (auto j = i ; j < i + 13 ; ++j)
std::cout << " "[i==j] << *j;
std::cout << std::endl;
}
return EXIT_SUCCESS;
}
//