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 62 63 64 65 66 67 68 69 70
|
I been playing around with this idea. This is my deck struct. So you can kinda see how i shuffled and labeled the cards in the vector.
[code]
struct deck {
int card1, card2, card3, card4, card5, card6, card7, card8, card9, card10, card11, card12, card13;
string _deck[4][13];
vector < pair<string, int>> shuffledDeck;
int deck1[4][13];
deck()
: card1(1),card2(2),card3(3),card4(4),card5(5), card6(6), card7(7), card8(8), card9(9), card10(10), card11(11), card12(12), card13(13),deck1{
card1,card2,card3,card4,card5, card6, card7, card8, card9, card10, card11, card12, card13,card1,card2,card3,card4,card5, card6, card7, card8,
card9, card10, card11, card12, card13,card1,card2,card3,card4,card5, card6, card7, card8, card9, card10, card11, card12, card13,card1,card2,card3,
card4,card5, card6, card7, card8, card9, card10, card11, card12, card13 } {}
void shuffle() {
srand(time(0));
while (!done()) {
int rand2 = rand() % 13;
int rand1 = rand() % 4; //heart == 0, diamonds==1 spades == 2 clubs == 3
if (rand1 == 0 && this->deck1[rand1][rand2] != 0) {
this->shuffledDeck.push_back(make_pair("hearts", this->deck1[rand1][rand2] + 1));
this->deck1[rand1][rand2] = 0;
}
else if (rand1 == 1 && this->deck1[rand1][rand2] != 0) {
this->shuffledDeck.push_back(make_pair("diamonds", this->deck1[rand1][rand2] + 1));
this->deck1[rand1][rand2] = 0;
}
else if (rand1 == 2 && this->deck1[rand1][rand2] != 0) {
this->shuffledDeck.push_back(make_pair("spades", this->deck1[rand1][rand2] + 1));
this->deck1[rand1][rand2] = 0;
}
else if (rand1 == 3 && this->deck1[rand1][rand2] != 0) {
this->shuffledDeck.push_back(make_pair("clubs", this->deck1[rand1][rand2] + 1));
this->deck1[rand1][rand2] = 0;
}
}
//return this->shuffledDeck;
}
bool done() {
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 13; x++) {
if (this->deck1[y][x] != 0) { return false; }
}
}
return true;
}
deck deckNew() {
deck d;
d.shuffle();
this->shuffledDeck = d.shuffledDeck;
return *this;
}
void displaydeck() {
for (int i = 0; i < this->shuffledDeck.size(); i++) {
cout << this->shuffledDeck[i].second << " of " << this->shuffledDeck[i].first << "\n";
}
cout << "decksize " << this->shuffledDeck.size() << "\n";
}
};
|