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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <string>
#include <iostream>
#include <deque>
#include <vector>
#include <random>
#include <algorithm>
#include <ctime>
using namespace std;
const string suit[] = {"D", "H", "S", "C"};
const string facevalue[] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
deque<string> the_deck =[] {
deque<string> result;
for (int i = 0 ; i < 52 ; ++i) {
result.push_back(facevalue[i % 13] + suit[i % 4]);
}
auto eng = default_random_engine(random_device()());
srand(time(0));
shuffle(begin(result), end(result), eng);
return result;
}();
string getCard () {
auto result = the_deck.front();
the_deck.pop_front();
return result;
}
void print_hand(vector<string>& hand) {
char choice = 'a';
auto sep = "";
for(auto& card : hand) {
cout << sep << "(" << choice << ")" << card;
sep = " ";
++choice;
}
}
using hand_type = vector<string>;
using player_hands_type = vector<hand_type>;
int main () {
const int DEAL_CARDS = 7; //number of cards we can deal to each player
const int PLAYERS = 5; //number of players
player_hands_type hands;
srand(time(0));
for (int player = 0 ; player < PLAYERS ; ++player) {
hand_type hand;
generate_n(back_inserter(hand), DEAL_CARDS, getCard);
hands.push_back(move(hand));
}
print_hand(hands[0]);
cout << "\n\nWhich one to replace? ";
return 0;
}
|