void one_run(){ Deck d; //d.print_deck(); Hand h1(d); // // Card c1(1,0); // h1.Addcard(c1); // Card c2(1,1); // h1.Addcard(c2); // Card c3(1,2); // h1.Addcard(c3); // Card c4(1,3); // h1.Addcard(c4); // Card c5(11,0); // h1.Addcard(c5); // Card c6(4,0); // h1.Addcard(c6); // Card c7(3,0); // h1.Addcard(c7); h1.Addcard(d.Deal()); h1.Addcard(d.Deal()); h1.Addcard(d.Deal()); h1.Addcard(d.Deal()); h1.Addcard(d.Deal()); h1.Pokerrank(); // h1.Printhand(); hist[h1.Get_prank()]++; }
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; if(players>10){ cout<<you need to reduce the number of player<<endl; return 0; } // deck.Shuffle(); Hand hands[players]; for(int j=0;j<5;j++){ int playercount = players; vector<Card> cardmain = deck.Deal(playercount); for(int i =0; i<players;i++){ hands[i].add(cardmain[i]); } } for(int j=0;j<players;j++){ hands[j].check(); hands[j].showHand(); cout<<" "<<hands[j].valueforplayer<<endl; } for(int i=0;i<players;i++){ hands[i].showHand(); cout<<" "<<hands[i].valueforplayer<<endl; } return 0; }
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; }
void one_run(){ Deck d; //d.print_deck(); Hand h1(d); Hand h2(d); // Card c1(8,0); // h1.Addcard(c1); // Card c2(3,1); // h1.Addcard(c2); // Card c3(13,2); // h1.Addcard(c3); // Card c4(12,3); // h1.Addcard(c4); // Card c5(11,1); // h1.Addcard(c5); // Card c6(10,0); // h1.Addcard(c6); // Card c7(13,0); // h1.Addcard(c7); //// for (int i = 0; i < 5; i++){ Card c = d.Deal(); h1.Addcard(c); h2.Addcard(c); } h1.Pokerrank(); // h1.Printhand(); h2.Pokerrank(); // h2.Printhand(); // cout << endl; // cout << endl; // hist[h1.Get_prank()]++; }
/* * * 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; }
void Game::Play() { //deal initial 2 cards to everyone vector<Player>::iterator pPlayer; for (int i = 0; i < 2; ++i) { for (pPlayer = m_Players.begin(); pPlayer != m_Players.end(); ++pPlayer) m_Deck.Deal(*pPlayer); m_Deck.Deal(m_House); } //hide house's first card m_House.FlipFirstCard(); //display everyone's hand for (pPlayer = m_Players.begin(); pPlayer != m_Players.end(); ++pPlayer) cout << *pPlayer << endl; cout << m_House << endl; //deal additional cards to players for (pPlayer = m_Players.begin(); pPlayer != m_Players.end(); ++pPlayer) m_Deck.AdditionalCards(*pPlayer); //reveal house's first card m_House.FlipFirstCard(); cout << endl << m_House; //deal additional cards to house m_Deck.AdditionalCards(m_House); if (m_House.IsBusted()) { //everyone still playing wins for (pPlayer = m_Players.begin(); pPlayer != m_Players.end(); ++pPlayer) if (!(pPlayer->IsBusted())) pPlayer->Win(); } else { //compare each player still playing to house for (pPlayer = m_Players.begin(); pPlayer != m_Players.end(); ++pPlayer) if (!(pPlayer->IsBusted())) { if (pPlayer->GetTotal() > m_House.GetTotal()) pPlayer->Win(); else if (pPlayer->GetTotal() < m_House.GetTotal()) pPlayer->Lose(); else pPlayer->Push(); } } //remove everyone's cards for (pPlayer = m_Players.begin(); pPlayer != m_Players.end(); ++pPlayer) pPlayer->Clear(); m_House.Clear(); }
int main() { Deck myDeck; Player me; int playerCardCount = 0; int dealerCardCount = 0; string userResponse; cout << "Would you like to play?: "; cin >> userResponse; if(userResponse == "Y" || userResponse == "y") { myDeck.shuffle(); } //Deal a game vector<Card> playersCards; vector<Card> dealerCards; playersCards.push_back(myDeck.Deal()); playersCards.push_back(myDeck.Deal()); cout << "Your Cards: " << playersCards[0].getVal() << " " << playersCards[1].getVal() << endl; //Dealer Cards dealerCards.push_back(myDeck.Deal()); dealerCards.push_back(myDeck.Deal()); playerCardCount = 2; cout << "Dealer showing: " << dealerCards[1].getVal() << endl; if(me.getHandValue(&playersCards) == 21) { cout << "BLACKJACK" << endl; me.setBankroll(me.getBankroll() + (me.getBetAmmount() * 1.5)); } cout << "Hit(H) Double(D) or Stand(S): "; cin >> userResponse; while(userResponse == "H" && (me.getHandValue(&playersCards) <= 21)) { playerCardCount++; playersCards.push_back(myDeck.Deal()); cout << "Your Cards: "; for(int i = 0; i < playersCards.size(); i++) { cout << playersCards[i].getVal() << " "; } cout << endl; cout << "Hand Value: " << me.getHandValue(&playersCards) << endl; cout << "Hit(H) Double(D) or Stand(S): "; cin >> userResponse; } //Dealers turn while(me.getHandValue(&dealerCards) < 17) { dealerCards.push_back(myDeck.Deal()); } cout << "Dealer's Hand: "; for(int i = 0; i < dealerCards.size(); i++) { cout << dealerCards[i].getVal() << " "; } cout << endl; if(me.getHandValue(&dealerCards) > 21) { cout << "YOU WIN"; me.setBankroll(me.getBankroll() + me.getBetAmmount()); } else if(me.getHandValue(&dealerCards) > me.getHandValue(&playersCards)) { cout << "YOU LOSE"; me.setBankroll(me.getBankroll() - me.getBetAmmount()); } else if(me.getHandValue(&playersCards) > me.getHandValue(&dealerCards)) { cout << "YOU WIN"; me.setBankroll(me.getBankroll() + me.getBetAmmount()); } cin >> userResponse; return 0; }
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; } } }
int Player::Play (int people, Deck &Main, Deck &layout, Card card) { // each round's play //Print who's turn. system("cls"); cout << "=====================It\'s " << name << "\'s turn.=====================\n\n"; int X, Y, success=0, count=0, max=0, min=0, index_x=0, index_y=0, index=0; char menu; Deck temp_deck; vector<int_pair> Pair; //Print out layout and hand cards. cout << "Layout:\n"; layout.Print(); cout << "\nCards in hand:\n"; Hand.Print(); for(unsigned int i=0; i<Find_match(Hand,layout).size(); i++) Pair.push_back( Find_match(Hand,layout).at(i) ); //Show auto quick search. if( Print_match_first(Hand,layout,Pair)==1 ) menu = '1'; else menu = '2'; //First stage MENU1: switch(menu){ case '1': //Computer Operation if( ComputerOn()==true ){ max = static_cast<int>(Hand.card(Pair.at(0).x).Points(people))+static_cast<int>(layout.card(Pair.at(0).y).Points(people)); index_x = Pair.at(0).x; index_y = Pair.at(0).y; for(unsigned int i=0; i<Pair.size(); i++){ if( static_cast<int>(Hand.card(Pair.at(i).x).Points(people))+static_cast<int>(layout.card(Pair.at(i).y).Points(people)) > max ){ max = static_cast<int>(Hand.card(Pair.at(i).x).Points(people))+static_cast<int>(layout.card(Pair.at(i).y).Points(people)); index_x = Pair.at(i).x; index_y = Pair.at(i).y; } } } cout << "\nI want to use my <X>th card to capture the <Y>th card.\n"; //Choose which cards to capture and to be captured. cout << "X = "; //Computer Operation if( ComputerOn()==true ){ cout << int_to_char(index_x); Sleep(TIME_CONSTANT); X = index_x; } else X = GetKey(); cout << endl; if( X<0 || X>Hand.number()-1 ){ cout << "\nYour input index is out of range!!\n"; goto MENU1; } cout << "Y = "; //Computer Operation if( ComputerOn()==true ){ cout << int_to_char(index_y); Sleep(TIME_CONSTANT); Y = index_y; } else Y = GetKey(); if( Y<0 || Y>layout.number()-1 ){ cout << "\nYour input index is out of range!!\n"; goto MENU1; } //Capture and print the message. success = CaptureCard( X, Y, Hand, layout); if( success == 1 ){ system("cls"); cout << "Layout:\n"; layout.Print(); cout << "\nCards in hand:\n"; Hand.Print(); cout << "\nNumber of captured cards: " << Pile.number() << endl; } else{ cout << "\nSorry, this action is invalid.\n"; goto MENU1; } break; case '2': cout << "\nNo cards are to be captured.\n"; cout << "I want to discard my <X>th card. "; //Choose which card to be discarded to the layout. cout << "X = "; //Computer operation if( ComputerOn()==true ){ min = Hand.card(0).Points(people); index = 0; for(int i=0; i<Hand.number(); i++){ if( Hand.card(i).Points(people)<min ){ min = Hand.card(i).Points(people); index = i; } } X = index; cout << int_to_char(X); Sleep(TIME_CONSTANT); } else X = GetKey(); cout << endl; if( X<0 || X>Hand.number()-1 ){ cout << "\nYour input index is out of range!!\n"; goto MENU1; } //Discard. layout.Add(Hand.card(X)); Hand.Delete(X); //Print. system("cls"); cout << "Layout:\n"; layout.Print(); cout << "\nCards in hand:\n"; Hand.Print(); break; default: goto MENU1; break; } //Second stage cout << "\nNow we are going to flip a card from the deck.\n"; //Simulate the flipping process. cout << "Waiting"; for(int i=6; i>=0; i--){ Sleep(130*i); cout << '.'; } //Print the flipped card. cout << "\nThe flipped card is: "; Main.card(Main.number()-1).Print(); cout << endl; //Special-case check for three cards. if( Main.card(Main.number()-1).rank_name()==card.rank_name() ){ cout << "\nNow the layout contains three cards of rank \"" << card.rank_name() << ".\"" << endl << endl; cout << "This is the special case." << endl; cout << "You are going to capture the three cards on the layout with your "; if( Main.card(Main.number()-1).suit_name() == "Diamond" || Main.card(Main.number()-1).suit_name() == "Heart" ) SetColor(4,7); else SetColor(0,7); cout << Main.card(Main.number()-1).suit_icon() << Main.card(Main.number()-1).rank_name(); SetColor(); cout << ".\n\n"; layout.Sort(); //Capture for(int i=0; i<layout.number() && count<3; i++){ if( layout.card(i).rank_name()==card.rank_name() ){ GetCardToPile(layout.card(i)); layout.Delete(i); count++; i--; } } GetCardToPile(Main.Deal()); cout << "Capturing"; for(int i=5; i>=0; i--){ Sleep(500); cout <<'.'; } cout << endl << endl; cout << "Now you have captured all cards of rank \"" << card.rank_name() << ".\"\n"; cout << "\nNumber of your all captured cards: " << Pile.number() << endl; cout << "\nYour turn is going to finish.\n"; cout << "\nPress any key to continue..."; cin.sync(); //Computer operation if( ComputerOn()==true ) PressAnyKey(); getch(); return 0; } //Show auto quick search. temp_deck.Add(Main.card(Main.number()-1)); if( Print_match_second(layout,Find_match(temp_deck,layout))==1 ) menu = '1'; else menu = '2'; MENU2: switch(menu){ case '1': cout << "\nI want to capture the <X>th card. "; //Choose which cards to capture and to be captured. cout << "X = "; //Computer operation temp_deck.Clear(); Pair.clear(); temp_deck.Add(Main.card(Main.number()-1)); for(unsigned int i=0; i<Find_match(temp_deck,layout).size(); i++) Pair.push_back( Find_match(temp_deck,layout).at(i) ); if( ComputerOn()==true ){ int max = static_cast<int>(Main.card(Main.number()-1).Points(people))+static_cast<int>(layout.card(Pair.at(0).y).Points(people)); int index = Pair.at(0).y; for(unsigned int i=0; i<Pair.size(); i++){ if( static_cast<int>(Main.card(Main.number()-1).Points(people))+static_cast<int>(layout.card(Pair.at(i).y).Points(people)) > max ){ max = static_cast<int>(Main.card(Main.number()-1).Points(people))+static_cast<int>(layout.card(Pair.at(i).y).Points(people)); index = Pair.at(i).y; } } cout << int_to_char(index); Sleep(TIME_CONSTANT); X = index; } else X = GetKey(); cout << endl; //Capture and print the message. success = CaptureCard( Main.number()-1, X, Main, layout); if( success == 1 ){ system("cls"); cout << "Layout:\n"; layout.Print(); cout << "\nCards in hand:\n"; Hand.Print(); cout << "\nNumber of captured cards: " << Pile.number() << endl; } else{ cout << "Sorry, this action is invalid.\n"; goto MENU2; } break; case '2': cout << "\nNo cards are to be captured.\n"; cout << "Put the card on the layout directly.\n"; layout.Add(Main.Deal()); cout << "Press any key to continue..."; //Computer operation if( ComputerOn()==true ) PressAnyKey(); getch(); //Print. system("cls"); cout << "Layout:\n"; layout.Print(); cout << "\nCards in hand:\n"; Hand.Print(); break; default: goto MENU2; break; } cout << "\nYour turn is going to finish.\n"; cout << "\nPress any key to continue....\n"; //Computer operation if( ComputerOn()==true ) PressAnyKey(); getch(); return 0; }