TEST(DeckTest, The52CardDeckShuffles) { Deck d; d.Shuffle(); Card* c1 = d.Next(); Card* c2 = d.Next(); Card* c3 = d.Next(); Card* c4 = d.Next(); d.Shuffle(); EXPECT_FALSE(d.Next()->Value() == c1->Value() && d.Next()->Value() == c2->Value() && d.Next()->Value() == c3->Value() && d.Next()->Value() == c4->Value()); }
int main() { Deck deck; deck.Display(); deck.Shuffle(); deck.Display(); return 0; }
int main(){ Deck a; a.Shuffle(); a.Show(); system("pause"); }
int main(){ Deck a; a.Shuffle(); Hand s1(&a), s2(&a); cout << "[Player A] Hand¡G"; s1.Show(); cout << "[Player B] Hand¡G"; s2.Show(); Hand::whoWin(s1, s2); system("pause"); }
int main() { vector< Hand > hands; Deck deck; int players; int seed; int sizeOfHand = 5; cout << "Enter seed: "; cin >> seed; srand(unsigned(seed)); cout << "Enter number of players: "; cin >> players; deck.Shuffle(); Hand abc[players]; /* * This vector named storeCards will take no of cards from the deck * which is equal to the no of players and the size of each hand which is fixed. */ vector<Card> storeCards = deck.Deal(players * sizeOfHand); int position = 0; /* * This series of loops will add the cards into the vector. */ for(int k = 0 ; k < sizeOfHand ; k++) { for(int i = 0 ; i < players ;i++) { abc[i].add(storeCards[position]); position++; } } /* * This loop will check the condition on the cards distributed to every player. */ for(int j = 0 ; j < players ;j++) { cout<< "Player "<<j+1<<" hand: "; abc[j].showHand(); abc[j].check(); cout<<endl; } }
int main() { Deck deck; int players; int seed; int sizeOfHand = 5; cout << "Enter seed: "; cin >> seed; srand(unsigned(seed)); cout << "Enter number of players: "; cin >> players; vector< Hand > hands(players); deck.Shuffle(); /* Deal cards from the deck and do a round robin distribution to the * players. Thus, if you had 5 players, and they each needed 5 cards you * would pull 5 cards off the deck and assign the first card to player one, * the second to player 2, etc.. Then you would deal 5 more and repeat the * process until 25 cards are dealt */ for(int j=0;j<sizeOfHand;j++){ vector< Card > cardsDeal = deck.Deal(players); int k=0; for(vector<Hand> ::iterator i= hands.begin();i!=hands.end();i++){ i->add(cardsDeal.at(k)); k++; } } /* For loop prints the final output. */ int j=1; for(vector<Hand> ::iterator i= hands.begin();i!=hands.end();i++){ cout<<"Player "<<j<<" hand: "; i->showHand(); j++; } return 0; }
int main() { Deck* d = new Deck(2); // std::cout << "### BEFORE SHUFFLE ###\n" << std::endl; // // for(int i = 0; i < d->m_deck.size(); i++) // { // std::cout << "Card: "; // d->m_deck[i]->PrintCard(); // std::cout << std::endl; // } // // std::cout << "\n\n### AFTER SHUFFLE ###\n" << std::endl; d->Shuffle(); for(int i = 0; i < d->m_deck.size(); i++) { //std::cout << "Suffle: "; d->m_deck[i]->PrintCard(); std::cout << std::endl; } // Card* c; // // std::cout << "Top of the deck: "; // d->m_deck.back()->PrintCard(); // // c = d->DealCard(); // // std::cout << "\nCard dealt: "; // c->PrintCard(); // // std::cout << "\nTop of the deck: "; // d->m_deck.back()->PrintCard(); // // std::cout << "\nSize: " << d->m_deck.size() << std::endl; return 0; }
/* * * I took a brute force approach to this, using some rough math first to know that I should start around 18-20, * After one day, I found a 19 card deal without a set, then continued on with 20 * this random guesser with infinite loops took 5 days on a powerful computer to randomly find the 20 nonset deal * There was a 1 in 4,694,436,188,839,116,720 (I think) chance of this happening per iteration! (I got lucky on the random) * I ran it on 21, but by the deadline the 20 is all I found. I think that this is the true largest anyway * Here's the output of the 20 cards it found without a set: A Purple Striped Oval with the number 1 A Green Striped Diamond with the number 2 A Green Solid Oval with the number 1 A Purple Open Squiggle with the number 3 A Purple Solid Squiggle with the number 2 A Purple Solid Oval with the number 1 A Purple Solid Squiggle with the number 1 A Green Striped Diamond with the number 1 A Purple Solid Oval with the number 2 A Green Open Diamond with the number 3 A Green Solid Oval with the number 2 A Green Striped Oval with the number 1 A Red Striped Diamond with the number 3 A Purple Striped Oval with the number 2 A Purple Striped Squiggle with the number 3 A Green Solid Diamond with the number 3 A Green Striped Oval with the number 2 A Green Solid Squiggle with the number 3 A Purple Striped Diamond with the number 3 A Red Solid Squiggle with the number 3 * Average number of available sets at - * 12: 12!/(9!3!) * 1/79 = 2.78... * 18: 18!/(15!3!) * 1/79 = 10.33 * 19: 19!/(16!3!) * 1/79 = 12.27 * 20: 20!/(17!3!) * 1/79 = 14.43 * */ void SetGame::findLargestNonSet() { vector<Card> NoSetCards; vector<Card> testCards; Deck testDeck; int startNum = 19; for (int num = 0; num < 3; num++) { // this will run for a long time and has a small chance of succeeding!!! for (int i = 0; i < 10000; i++) // while (true) { testDeck.Shuffle(); testDeck.Deal(startNum + num, testCards); if (findAllSets(testCards, false).size() == 0) { cout << "Found no sets in a deal of " << startNum + num << " cards. Continuing with " << startNum + num + 1 << endl; NoSetCards = testCards; break; } else if (i % 100 == 0) { cout << "Testing " << startNum + num << " the " << i << "th time" << endl; } else if (i == 9999) { cout << "Found sets in 10000 random deals of " << startNum + num << " cards" << endl; goto END; } testDeck.Replace(testCards); } } END: printCards(NoSetCards); int x; cin >> x; }
int main(int argc, const char * argv[]) { Deck d; int M = 100000; // Num of trials //cout << "Please Enter The Num of Players" << endl; int N; cin >> N; vector<Player> players(N); for (int i = 0; i < N; i++){ //cout << "Please Enter the Hole Hands for player " << i+1 << endl; string card1str, card2str; cin >> card1str >> card2str; Card* X1 = NULL; Card* X2 = NULL; while (true) { X1 = d.Deal(readCard(card1str.substr(1)), readCard(card1str[0])); X2 = d.Deal(readCard(card2str.substr(1)), readCard(card2str[0])); if (X1 == NULL || X2 == NULL) { cout << "The cards are invalid Please re-enter" << endl; } else { break; } } players[i].readCard(X1); players[i].readCard(X2); } for (int n = 0; n <= 5; n++){ switch (n) { case 0: cout << "-------------------Pre Flop--------------------" << endl; break; case 4: cout << "-------------------Flop------------------------" << endl; break; case 5: cout << "-------------------Turn------------------------" << endl; break; /*case 5: cout << "-------------------River-----------------------" << endl; break;*/ default: break; } if (n > 0) { Card *X = NULL; while (true) { string cardstr; cin >> cardstr; X = d.Deal(readCard(cardstr.substr(1)), readCard(cardstr[0])); if (X == NULL) { cout << "The card " << n << " is invalid Please re enter" << endl; } else break; } for (int i = 0; i < N; i++){ players[i].readCard(X); } } if (n == 1 || n == 2) continue;// No need for first and second FLOP card /* Monte Carlo */ int trials = 0; if (n == 5) trials = 10000; // no more need if all cards come out while (trials++ < M) { while (players[0].getNumHands() != 7) { Card* new_card = d.Deal(); //cout << new_card->toString() << " "; for (int i = 0; i < N; i++) { players[i].readCard(new_card); } } //cout << endl; for (int i = 0; i < N; i++) { players[i].genSuite(); } vector<int> winners = judgeWinners(players); if (n == 5) { if (winners.size() == 1){ cout << "Winner: Player " << winners[0] + 1 << endl; } else { cout << "Split by: " << endl; for (int i = 0; i < winners.size(); i++) { cout << "Player " << i+1 << endl; } } for (int i = 0; i < N; i++) { cout << "Player " << i+1 << " hands: " << players[i].toString() << endl; } return 0; } d.Shuffle(N*2+n); // keep the player's cards and shuffle remainings for (int i = 0; i < N; i++) { players[i].removeCards(2+n); } } cout << "/* Monte Carlo Simulation */" << endl; for (int i = 0; i < N; i++) { cout << "Player " << i+1 << ": win " << players[i].winHands << " split " << players[i].splitHands << endl; players[i].winHands = 0; players[i].splitHands = 0; } /* Calculate Actual Prob for Turn and River */ if (n == 4 || n == 3) { int remainningCards = (int)d.validCards.size(); for (int i = 0; i < remainningCards; i++) { if (n == 3) { for (int k = i+1; k < remainningCards; k++) { for (int j = 0; j < N; j++) { players[j].readCard(d.validCards[i]); players[j].readCard(d.validCards[k]); players[j].genSuite(); } vector<int> winners = judgeWinners(players); for (int i = 0; i < N; i++) { players[i].removeCards(2+n); } } } if (n == 4) { for (int j = 0; j < N; j++) { players[j].readCard(d.validCards[i]); players[j].genSuite(); } vector<int> winners = judgeWinners(players); for (int i = 0; i < N; i++) { players[i].removeCards(2+n); } } } int totalHands = remainningCards; if (n == 3) { totalHands = remainningCards * (remainningCards-1)/2; } cout << "/* Actual Probability */" << endl; for (int i = 0; i < N; i++) { cout << "Player " << i+1 << ": win rate " << players[i].winHands/(double)totalHands << " split rate " << players[i].splitHands/(double)totalHands << endl; players[i].winHands = 0; players[i].splitHands = 0; } } }