// Programmieren 1, Praktikum 5, Aufgabe 4 // Sven Eisenhauer // 10.01.2005 // // file: main.cpp // // purpose: Shuffle a standard deck of 52 cards, deal a poker game and analyse the cards of the player // #include using std::cin; using std::cout; using std::endl; using std::left; using std::right; #include using std::setprecision; using std::setw; // contains function prototypes for functions srand and rand #include #include const int maxColumns=13; const int maxRows=4; const int maxCards=52; const int cards=7; const int maxResults=10; const int nrGames=1000000; struct hand { const char *farbe; const char *wert; }; // prototypes void shuffle( int [][ maxColumns ] ); void deal( const int [][ maxColumns ], const char *[], const char *[], hand[] ); void printHand(const hand []); void analyseCards(const hand[], const char *[], const char *[],int[],const char *[]); void printResults(const int[],const char *[]); int onePair(const hand[], const char *[]); int twoPairs(const hand[], const char *[]); int threeOfAKind(const hand[], const char *[]); int straight(const hand[], const char *[]); int flush(const hand[], const char *[]); int fullHouse(const hand[], const char *[]); int fourOfAKind(const hand[], const char *[]); int straightFlush(const hand[], const char *[], const char *[]); int royalFlush(const hand[], const char *[], const char *[]); int main() { hand blatt[cards]; int erg[maxResults]={0}; const char *results[maxResults] = { "Nothing","One Pair","Two Pairs","Three of a kind", "Straight","Flush","Full house","Four of a kind", "Straight Flush","Royal Flush" }; // initialize suit array const char *suit[ 4 ] = { "Hearts", "Diamonds", "Clubs", "Spades" }; // initialize face array const char *face[ 13 ] = { "Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" }; // initialize deck array int deck[ maxRows ][ maxColumns ] = { { 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 } }; srand( time( 0 ) ); // seed random number generator for (int n=1;n<=nrGames;n++) { shuffle( deck ); deal( deck, face, suit, blatt ); //printHand(blatt); analyseCards(blatt,face,suit,erg,results); } printResults(erg,results); return 0; // indicates successful termination } // end main void printHand(const hand blatt[]) { cout << endl << endl << "Player's cards:" << endl; for (int i=0;i