// estimate the probility that a flush will occur when poker // hands are dealt. A flush occurs when at least five cards // are of the same suit #include #include #include "poker1.h" void main() { card one_hand[9]; // max of 9 cards per hand deck dk; int fcnt = 0; // used for flush count int sval[4]; // the number of cards of a particular // suit value found in the hand int ndeal; // number of deals int nc; // number of cards dealt to each hand int nhand; // number of hands to be dealt with the deck int i, j; do { cout << "\nEnter no. cards in a hand (5-9): "; cin >> nc; } while (nc < 5 || nc > 9); nhand = 52 / nc; cout << "\nEnter no. of deals: "; cin >> ndeal; srand(time(NULL)); // seed rand() from time(); init_deck(dk); print_deck(dk); for (int k = 0; k < ndeal; k += nhand) { if ((nhand + k) > ndeal) // the last time a deck needs to nhand = ndeal - k; // be shuffled. shuffle(dk); for (i = 0; i < nc * nhand; i += nc) { for (j = 0; j < 4; j++) sval[j] = 0; // zero suit counts deal(nc, i, one_hand, dk); // deal next hand for (j = 0; j < nc; j++) sval[one_hand[j].s]++; // increment suit count for (j = 0; j < 4; j++) if (sval[j] >= 5) // 5 or more is flush fcnt++; } } cout << "\n\nIn " << ndeal << " "; cout << nc << "-card hands there were "; cout << fcnt << " flushes\n "; }