# Winning Conditions for Poker.

Discussion in 'C' started by dankbc1, Oct 19, 2008.

1. ### dankbc1New Member

Joined:
Oct 19, 2008
Messages:
4
0
Trophy Points:
0
I've written the winning conditions for pair, high card and three of a kind. However, I am very confused on how to write the winning conditions for a royal flush, straight flush, four of a kind, full house, flush, and straight. Can anyone here please point me in the right direction? I would greatly appreciate it.

My code is below:

Code:
```#include <iostream>
#include <ctime>
#include <cmath>
#include <windows.h>
#include <cstdlib>

using namespace std;

int compMONEYONE, compMONEYTWO, compMONEYTHREE, compMONEYFINAL;
int compMONEY = 1000;
int playerMONEY = 1000;
int compBETONE, compBETTWO, compBETTHREE, compBETFINAL;
int placeBETONE, placeBETTWO, placeBETTHREE, placeBETFINAL;
int card;
int suitC;
int rankC;

const char* rank[] = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
const char* suit[] = {"Hearts!", "Spades!", "Diamonds!", "Shamrock!"};

int numPlayers;
//	int random;

char choice;
char PlayAgain;
char winner;

void preGame()
{
srand(GetTickCount());

//loop so that all the cards are different, if one is the same as another, the loop restarts
do
{
//random number from 1-52 which is a card deck
card = ((rand() % 52) + 1);
//cout << card << endl;
card = ((rand() % 52) + 1);
card = ((rand() % 52) + 1);
card = ((rand() % 52) + 1);
card = ((rand() % 52) + 1);
card = ((rand() % 52) + 1);
card = ((rand() % 52) + 1);
}while(card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card || card == card);

//ranks - ace, one, two, three, four, five, six, seven, eight, nine, ten, jack, queen, king
//remainder of number which then goes through the console testing loop
//ranks are all different or loop restarts

rankC = (card % 13);
//cout << rank << endl;
rankC = (card % 13);
//cout << rank << endl;
rankC = (card % 13);
//cout << rank << endl;
rankC = (card % 13);
//cout << rank << endl;
rankC = (card % 13);
//cout << rank << endl;
rankC = (card % 13);
//cout << rank << endl;
rankC = (card % 13);
//cout << rank << endl;

//4 suits - hearts, spades, shamrocks, diamonds
suitC = (rand() % 4);
suitC = (rand() % 4);
suitC = (rand() % 4);
suitC = (rand() % 4);
suitC = (rand() % 4);
suitC = (rand() % 4);
suitC = (rand() % 4);

/*	if(numPlayers > 5 || numPlayers < 1)
{
cout << "Please enter the number of players that you would like to include in this game(no more than 5): ";
cin >> numPlayers;
}*/
}

void betGame()
{

cout << "Player Money Total: \$" << playerMONEY << endl;
cout << "Computer Money Total: \$" << compMONEY << endl;
//    random = (rand() % 1);

//    if(random == 0)
//    {
cout << "Small blind: \$25 put up by the computer." << endl;
cout << "Big blind: \$50 put up by the player." << endl;
cout << "Player Money Total: \$" << playerMONEY - 50 << endl;
cout << "Computer Money Total: \$" << compMONEY - 25 << endl;
compMONEYONE = compMONEY - 25;
/*    }
else
{
cout << "Small blind: \$25 put up by the player." << endl;
cout << "Big blind: \$50 put up by the computer." << endl;
cout << "Player Money Total: \$" << playerMONEY - 25 << endl;
cout << "Computer Money Total: \$" << compMONEY - 50 << endl;
}*/

cout << "Player's First Card: " << rank[rankC] << " of " << suit[suitC] << endl;

cout << "Player's Second Card: " << rank[rankC] << " of " << suit[suitC] << endl;

//SECOND YOU FLIP 1 CARD AND YOU SEE YOUR CARDS AND 1 CARD -- BET #2

cout << "How much would you like to bet?";
cin >> placeBETONE;
compBETONE = (rand() % compMONEYONE);
cout << "Computer bet: " << compBETONE << endl;
cout << "Player Money Total: \$" << playerMONEY - 50 - placeBETONE << endl;
cout << "Computer Money Total: \$" << compMONEY - 25 - compBETONE << endl;
compMONEYTWO = compMONEY - 25 - compBETONE;

cout << "Flop First Card: " << rank[rankC] << " of " << suit[suitC] << endl;

cout << "Flop Second Card: " << rank[rankC] << " of " << suit[suitC] << endl;

cout << "Flop Third Card: " << rank[rankC] << " of " << suit[suitC] << endl;

placeBETTWO = -1;
while(placeBETTWO < 0 || placeBETTWO > 25)
{
cout << "How much would you like to bet?";
cin >> placeBETTWO;
compBETTWO = (rand() % compMONEYTWO);
cout << "Computer bet: " << compBETTWO << endl;
cout << "Player Money Total: \$" << playerMONEY - 50 - placeBETONE - placeBETTWO << endl;
cout << "Computer Money Total: \$" << compMONEY - 25 - compBETONE - compBETTWO << endl;
compMONEYTHREE = compMONEY - 25 - compBETONE - compBETTWO;

cout << "Turn Card: " << rank[rankC] << " of " << suit[suitC] << endl;
}

placeBETTHREE = -1;
while(placeBETTHREE < 0 || placeBETTHREE > 25)
{
cout << "How much would you like to bet?";
cin >> placeBETTHREE;
compBETTHREE = (rand() % compMONEYTHREE);
cout << "Computer bet: " << compBETTHREE << endl;
cout << "Player Money Total: \$" << playerMONEY - 50 - placeBETONE - placeBETTWO - placeBETTHREE << endl;
cout << "Computer Money Total: \$" << compMONEY - 25 - compBETONE - compBETTWO - compBETTHREE << endl;
compMONEYFINAL = compMONEY - 25 - compBETONE - compBETTWO - compBETTHREE;

cout << "River Card: " << rank[rankC] << " of " << suit[suitC] << endl;;
}

placeBETFINAL = -1;
while(placeBETFINAL < 0 || placeBETFINAL > 25)
{
cout << "How much would you like to bet?";
cin >> placeBETFINAL;
compBETFINAL = (rand() % compMONEYFINAL);
cout << "Computer bet: " << compBETFINAL << endl;
cout << "Player Money Total: \$" << playerMONEY - 50 - placeBETONE - placeBETTWO - placeBETTHREE - placeBETFINAL << endl;
cout << "Computer Money Total: \$" << compMONEY - 25 - compBETONE - compBETTWO - compBETTHREE - compBETFINAL << endl;
}

//WINNING CONDITIONS

if((suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC) || (suitC == suitC && suitC == suitC && suitC == suitC && suitC == suitC))
{
if()
}
//THREE OF A KIND
if((rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC) || (rankC == rankC && rankC == rankC))
{
cout << winner << " wins with a three of a kind!" << endl;
}
//PAIR
else
if((rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC) || (rankC == rankC))
{
cout << winner << " wins with a pair!" << endl;
}
//HIGH CARD
else
if(rankC > rankC && rankC > rankC && rankC > rankC && rankC > rankC && rankC > rankC && rankC > rankC)
{
cout << winner << " wins with a high card: " << rankC << endl;
}
else
if(rankC > rankC && rankC > rankC && rankC > rankC && rankC > rankC && rankC > rankC && rankC > rankC)
{
cout << winner << " wins with a high card: " << rankC << endl;
}

cout << "Do You Want To Play Again: " << endl;
cin >> PlayAgain;
}

int main()
{
do
{
cout << "Welcome to Texas Hold 'Em!" << endl;

preGame();
betGame();

}while(PlayAgain == 'y');

}```

2. ### oogaboogaNew Member

Joined:
Jan 9, 2008
Messages:
115
11
Trophy Points:
0
If you are under no pressure to do this particular task, you may want to get a book or find a tutorial online and learn more about function arguments and processing arrays with loops.

For example, the deck should be an array of ints that is actually shuffled, which obivates the need to test for duplicate cards.
Code:
```#define VALUE(card) ((card) % 13)  // Values 0 to 12 (real value
//   is VALUE() + 1
#define SUIT(card) ((card) / 4)    // Suits 0 to 3

void deck_init (int *deck)
{
srand (time (0));                 // init rand()
for (int i = 0; i < 52; ++i)      // fill deck with 0 to 51
deck[i] = i;
}

void deck_shuffle (int *deck)
{
for (int i = 51; i > 1; --i)      // for each card in the deck
{
int r = rand() % (i + 1);     // choose a random position
int temp = deck[i];           // swap the cards
deck[i] = deck[r];
deck[r] = temp;
}
}
```
In analyzing the hands, you would use arrays to count the values and suits:
Code:
```int value;
int suit;

zero (value, 13);
zero (suit, 4);

for (int i = 0; i < CardsInHand; ++i)
{
++value[VALUE(hand[i])];
++suit[SUIT(hand[i])];
}
```
You can then process the value and suit arrays to determine if the hand is a straight or flush or whatever.

3. ### oogaboogaNew Member

Joined:
Jan 9, 2008
Messages:
115
`for (int i = 51; i > 0; --i)`