#include <iostream>
class Card
{
public:
int suit;
int rank;
private:
};
#include <vector>
using namespace std;
class Hand
{
public:
void addCard(Card c);
bool isFlush();
private:
vector<Card> myHand;
int suit;
};
using namespace std;
class Deck
{
public:
Deck();
void shuffleDeck();
Hand dealCards();
private:
vector<Card> myDeck;
};
bool Hand::isFlush()
{
bool result;
// Check for a flush (all the same suit)
if(myHand[0].suit == myHand[1].suit && myHand[0].suit== myHand[2].suit && myHand[0].suit==myHand[3].suit && myHand[0].suit==myHand[4].suit)
{
result = true;
}
else
{
result = false;
}
return result;
}
void Hand::addCard(Card c)
{
myHand.push_back(c);
}
#include<algorithm>
Deck::Deck()
{
for(int i=0; i<52;i++)
{
Card c;
c.suit=i/13;
c.rank=(i%13)+2;
myDeck.push_back(c);
}
}
void Deck::shuffleDeck()
{
random_shuffle(myDeck.begin(), myDeck.end());
}
Hand Deck::dealCards()
{
Hand result;
for(int i=0;i<5;i++)
{
result.addCard(myDeck[i]);
}
return result;
}
int main()
{
srand(time(0));
cout<<"Welcome to the Poker Experiment."<<endl;
Deck deck;
int flushCount=0;
int numberOfHands=500000;
for(int i=0; i<numberOfHands;i++)
{
deck.shuffleDeck();
Hand hand=deck.dealCards();
if(hand.isFlush())
{
flushCount++;
deck.shuffleDeck();
}
else
{
deck.shuffleDeck();
}
hand = deck.dealCards();
}
cout<<"Flush percentage = "
<< ((double)flushCount/(double)numberOfHands)*100.0<<endl;
cout << "Num flush: " << flushCount << endl;
cout << "Num hands: " << numberOfHands;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgQ2FyZAp7CnB1YmxpYzoKICAgIGludCBzdWl0OwogICAgaW50IHJhbms7CnByaXZhdGU6Cn07CgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjbGFzcyBIYW5kCnsKcHVibGljOgogICAgdm9pZCBhZGRDYXJkKENhcmQgYyk7CiAgICBib29sIGlzRmx1c2goKTsKcHJpdmF0ZToKICA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ZmbGUobXlEZWNrLmJlZ2luKCksIG15RGVjay5lbmQoKSk7CiAgICB9CiAgICBIYW5kIERlY2s6OmRlYWxDYXJkcygpCiAgICB7CiAgICAgICAgSGFuZCByZXN1bHQ7CiAgICAgICAgZm9yKGludCBpPTA7aTw1O2krKykKICAgICAgICB7CiAgICAgICAgICAgIHJlc3VsdC5hZGRDYXJkKG15RGVja1tpXSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXN1bHQ7CiAgICB9CgppbnQgbWFpbigpCnsKCXNyYW5kKHRpbWUoMCkpOwogICAgY291dDw8IldlbGNvbWUgdG8gdGhlIFBva2VyIEV4cGVyaW1lbnQuIjw8ZW5kbDsKICAgIERlY2sgZGVjazsKICAgIGludCBmbHVzaENvdW50PTA7CiAgICBpbnQgbnVtYmVyT2ZIYW5kcz01MDAwMDA7CiAgICBmb3IoaW50IGk9MDsgaTxudW1iZXJPZkhhbmRzO2krKykKICAgIHsKICAgICAgICBkZWNrLnNodWZmbGVEZWNrKCk7CiAgICAgICAgSGFuZCBoYW5kPWRlY2suZGVhbENhcmRzKCk7CiAgICAgICAgaWYoaGFuZC5pc0ZsdXNoKCkpCiAgICAgICAgewogICAgICAgICAgICBmbHVzaENvdW50Kys7CiAgICAgICAgICAgIGRlY2suc2h1ZmZsZURlY2soKTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgZGVjay5zaHVmZmxlRGVjaygpOwogICAgICAgIH0KICAgICAgICBoYW5kID0gZGVjay5kZWFsQ2FyZHMoKTsKICAgIH0KICAgIGNvdXQ8PCJGbHVzaCBwZXJjZW50YWdlID0gIgogICAgICAgIDw8ICgoZG91YmxlKWZsdXNoQ291bnQvKGRvdWJsZSludW1iZXJPZkhhbmRzKSoxMDAuMDw8ZW5kbDsKICAgIGNvdXQgPDwgIk51bSBmbHVzaDogIiA8PCBmbHVzaENvdW50IDw8IGVuZGw7CiAgICBjb3V0IDw8ICJOdW0gaGFuZHM6ICIgPDwgbnVtYmVyT2ZIYW5kczsKICAgIHJldHVybiAwOwp9Cg==