[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Winning Conditions for Poker.

daniel.kaner

10/19/2008 7:57:00 PM

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:

#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[7];
int suitC[7];
int rankC[7];

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[0] = ((rand() % 52) + 1);
//cout << card[0] << endl;
card[1] = ((rand() % 52) + 1);
card[2] = ((rand() % 52) + 1);
card[3] = ((rand() % 52) + 1);
card[4] = ((rand() % 52) + 1);
card[5] = ((rand() % 52) + 1);
card[6] = ((rand() % 52) + 1);
}while(card[0] == card[1] || card[0] == card[2] || card[0] ==
card[3] || card[0] == card[4] || card[0] == card[5] || card[0] ==
card[6] || card[1] == card[2] || card[1] == card[3] || card[1] ==
card[4] || card[1] == card[5] || card[1] == card[6] || card[2] ==
card[3] || card[2] == card[4] || card[2] == card[5] || card[2] ==
card[6] || card[3] == card[4] || card[3] == card[5] || card[3] ==
card[6] || card[4] == card[5] || card[4] == card[6] || card[5] ==
card[6]);

//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[0] = (card[0] % 13);
//cout << rank[0] << endl;
rankC[1] = (card[1] % 13);
//cout << rank[1] << endl;
rankC[2] = (card[2] % 13);
//cout << rank[2] << endl;
rankC[3] = (card[3] % 13);
//cout << rank[3] << endl;
rankC[4] = (card[4] % 13);
//cout << rank[4] << endl;
rankC[5] = (card[5] % 13);
//cout << rank[5] << endl;
rankC[6] = (card[6] % 13);
//cout << rank[6] << endl;

//4 suits - hearts, spades, shamrocks, diamonds
suitC[0] = (rand() % 4);
suitC[1] = (rand() % 4);
suitC[2] = (rand() % 4);
suitC[3] = (rand() % 4);
suitC[4] = (rand() % 4);
suitC[5] = (rand() % 4);
suitC[6] = (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[0]] << " of " <<
suit[suitC[0]] << endl;

cout << "Player's Second Card: " << rank[rankC[1]] << " of " <<
suit[suitC[1]] << 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[2]] << " of " <<
suit[suitC[2]] << endl;

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

cout << "Flop Third Card: " << rank[rankC[4]] << " of " <<
suit[suitC[4]] << 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[5]] << " of " <<
suit[suitC[5]] << 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[6]] << " of " <<
suit[suitC[6]] << 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[0] == suitC[1] && suitC[1] == suitC[2] && suitC[2]
== suitC[3] && suitC[3] == suitC[4]) || (suitC[0] == suitC[1] &&
suitC[1] == suitC[2] && suitC[2] == suitC[3] && suitC[3] == suitC[5])
|| (suitC[0] == suitC[1] && suitC[1] == suitC[2] && suitC[2] ==
suitC[3] && suitC[3] == suitC[6]) || (suitC[0] == suitC[1] && suitC[1]
== suitC[2] && suitC[2] == suitC[4] && suitC[4] == suitC[5]) ||
(suitC[0] == suitC[1] && suitC[1] == suitC[2] && suitC[2] == suitC[4]
&& suitC[4] == suitC[6]) || (suitC[0] == suitC[1] && suitC[1] ==
suitC[2] && suitC[2] == suitC[5] && suitC[5] == suitC[6]) || (suitC[0]
== suitC[1] && suitC[1] == suitC[3] && suitC[3] == suitC[4] &&
suitC[4] == suitC[5]) || (suitC[0] == suitC[1] && suitC[1] == suitC[3]
&& suitC[3] == suitC[4] && suitC[4] == suitC[6]) || (suitC[0] ==
suitC[1] && suitC[1] == suitC[3] && suitC[3] == suitC[5] && suitC[5]
== suitC[6]) || (suitC[0] == suitC[1] && suitC[1] == suitC[4] &&
suitC[4] == suitC[5] && suitC[5] == suitC[6]) || (suitC[0] == suitC[2]
&& suitC[2] == suitC[3] && suitC[3] == suitC[4] && suitC[4] ==
suitC[5]) || (suitC[0] == suitC[2] && suitC[2] == suitC[3] && suitC[3]
== suitC[4] && suitC[4] == suitC[6]) || (suitC[0] == suitC[2] &&
suitC[2] == suitC[3] && suitC[3] == suitC[5] && suitC[5] == suitC[6])
|| (suitC[0] == suitC[2] && suitC[2] == suitC[4] && suitC[4] ==
suitC[5] && suitC[5] == suitC[6]) || (suitC[0] == suitC[3] && suitC[3]
== suitC[4] && suitC[4] == suitC[5] && suitC[5] == suitC[6]) ||
(suitC[1] == suitC[2] && suitC[2] == suitC[3] && suitC[3] == suitC[4]
&& suitC[4] == suitC[5]) || (suitC[1] == suitC[2] && suitC[2] ==
suitC[3] && suitC[3] == suitC[4] && suitC[4] == suitC[6]) || (suitC[1]
== suitC[2] && suitC[2] == suitC[3] && suitC[3] == suitC[5] &&
suitC[5] == suitC[6]) || (suitC[1] == suitC[2] && suitC[2] == suitC[4]
&& suitC[4] == suitC[5] && suitC[5] == suitC[6]) || (suitC[1] ==
suitC[3] && suitC[3] == suitC[4] && suitC[4] == suitC[5] && suitC[5]
== suitC[6]) || (suitC[2] == suitC[3] && suitC[3] == suitC[4] &&
suitC[4] == suitC[5] && suitC[5] == suitC[6]))
{
if()
}
//THREE OF A KIND
if((rankC[0] == rankC[1] && rankC[1] == rankC[2]) || (rankC[0]
== rankC[1] && rankC[1] == rankC[3]) || (rankC[0] == rankC[1] &&
rankC[1] == rankC[4]) || (rankC[0] == rankC[1] && rankC[1] ==
rankC[5]) || (rankC[0] == rankC[1] && rankC[1] == rankC[6]) ||
(rankC[0] == rankC[2] && rankC[2] == rankC[3]) || (rankC[0] ==
rankC[2] && rankC[2] == rankC[4]) || (rankC[0] == rankC[2] && rankC[2]
== rankC[5]) || (rankC[0] == rankC[2] && rankC[2] == rankC[6]) ||
(rankC[0] == rankC[3] && rankC[3] == rankC[4]) || (rankC[0] ==
rankC[3] && rankC[3] == rankC[5]) || (rankC[0] == rankC[3] && rankC[3]
== rankC[6]) || (rankC[0] == rankC[4] && rankC[4] == rankC[5]) ||
(rankC[0] == rankC[4] && rankC[4] == rankC[6]) || (rankC[0] ==
rankC[5] && rankC[5] == rankC[6]) || (rankC[1] == rankC[2] && rankC[2]
== rankC[3]) || (rankC[1] == rankC[2] && rankC[2] == rankC[4]) ||
(rankC[1] == rankC[2] && rankC[2] == rankC[5]) || (rankC[1] ==
rankC[2] && rankC[2] == rankC[6]) || (rankC[1] == rankC[3] && rankC[3]
== rankC[4]) || (rankC[1] == rankC[3] && rankC[3] == rankC[5]) ||
(rankC[1] == rankC[3] && rankC[3] == rankC[6]) || (rankC[1] ==
rankC[4] && rankC[4] == rankC[5]) || (rankC[1] == rankC[4] && rankC[4]
== rankC[6]) || (rankC[1] == rankC[5] && rankC[5] == rankC[6]) ||
(rankC[2] == rankC[3] && rankC[3] == rankC[4]) || (rankC[2] ==
rankC[3] && rankC[3] == rankC[5]) || (rankC[2] == rankC[3] && rankC[3]
== rankC[6]) || (rankC[2] == rankC[4] && rankC[4] == rankC[5]) ||
(rankC[2] == rankC[4] && rankC[4] == rankC[6]) || (rankC[2] ==
rankC[5] && rankC[5] == rankC[6]) || (rankC[3] == rankC[4] && rankC[4]
== rankC[5]) || (rankC[3] == rankC[4] && rankC[4] == rankC[6]) ||
(rankC[3] == rankC[5] && rankC[5] == rankC[6]) || (rankC[4] ==
rankC[5] && rankC[5] == rankC[6]))
{
cout << winner << " wins with a three of a kind!" <<
endl;
}
//PAIR
else
if((rankC[0] == rankC[1]) || (rankC[0] == rankC[2]) ||
(rankC[0] == rankC[3]) || (rankC[0] == rankC[4]) || (rankC[0] ==
rankC[5]) || (rankC[0] == rankC[6]) || (rankC[0] == rankC[7]) ||
(rankC[1] == rankC[2]) || (rankC[1] == rankC[3]) || (rankC[1] ==
rankC[4]) || (rankC[1] == rankC[5]) || (rankC[1] == rankC[6]) ||
(rankC[2] == rankC[3]) || (rankC[2] == rankC[4]) || (rankC[2] ==
rankC[5]) || (rankC[2] == rankC[6]) || (rankC[3] == rankC[4]) ||
(rankC[3] == rankC[5]) || (rankC[3] == rankC[6]) || (rankC[4] ==
rankC[5]) || (rankC[4] == rankC[6]) || (rankC[5] == rankC[6]))
{
cout << winner << " wins with a pair!" << endl;
}
//HIGH CARD
else
if(rankC[0] > rankC[1] && rankC[0] > rankC[2] &&
rankC[0] > rankC[3] && rankC[0] > rankC[4] && rankC[0] > rankC[5] &&
rankC[0] > rankC[6])
{
cout << winner << " wins with a high card: " <<
rankC[0] << endl;
}
else
if(rankC[1] > rankC[0] && rankC[1] > rankC[2] &&
rankC[1] > rankC[3] && rankC[1] > rankC[4] && rankC[1] > rankC[5] &&
rankC[1] > rankC[6])
{
cout << winner << " wins with a high card: "
<< rankC[0] << 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');

}
7 Answers

red floyd

10/19/2008 9:10:00 PM

0

daniel.kaner@gmail.com wrote:
> 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.
>

[redacted]

No matter how many times you ask, we will *NOT* do your homework
for you. Ask your instructor.

See FAQ 5.2,

http://www.parashift.com/c++-faq-lite/how-to-post.ht...



daniel.kaner

10/19/2008 9:27:00 PM

0

On Oct 19, 5:10 pm, red floyd <no.spam.h...@example.com> wrote:
> daniel.ka...@gmail.com wrote:
> > 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.
>
> [redacted]
>
> No matter how many times you ask, we will *NOT* do your homework
> for you.  Ask your instructor.
>
> See FAQ 5.2,
>
> http://www.parashift.com/c++-faq-lite/how-to-post.ht...

Did I ask for answers? I asked you to please point me in the right
direction. Thanks for the useless post.

acehreli

10/19/2008 10:55:00 PM

0

On Oct 19, 12:56 pm, daniel.ka...@gmail.com wrote:
> 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?
[...]
>         if((suitC[0] == suitC[1] && suitC[1] == suitC[2] && suitC[2]
> == suitC[3] && suitC[3] == suitC[4]) || (suitC[0] == suitC[1] &&
> suitC[1] == suitC[2] && suitC[2] == suitC[3] && suitC[3] == suitC[5])
> || (suitC[0] == suitC[1] && suitC[1] == suitC[2] && suitC[2] ==
> suitC[3] && suitC[3] == suitC[6]) || (suitC[0] == suitC[1] && suitC[1]
> == suitC[2] && suitC[2] == suitC[4] && suitC[4] == suitC[5]) ||
> (suitC[0] == suitC[1] && suitC[1] == suitC[2] && suitC[2] == suitC[4]
> && suitC[4] == suitC[6]) || (suitC[0] == suitC[1] && suitC[1] ==
> suitC[2] && suitC[2] == suitC[5] && suitC[5] == suitC[6]) || (suitC[0]
> == suitC[1] && suitC[1] == suitC[3] && suitC[3] == suitC[4] &&
> suitC[4] == suitC[5]) || (suitC[0] == suitC[1] && suitC[1] == suitC[3]
> && suitC[3] == suitC[4] && suitC[4] == suitC[6]) || (suitC[0] ==
> suitC[1] && suitC[1] == suitC[3] && suitC[3] == suitC[5] && suitC[5]
> == suitC[6]) || (suitC[0] == suitC[1] && suitC[1] == suitC[4] &&
> suitC[4] == suitC[5] && suitC[5] == suitC[6]) || (suitC[0] == suitC[2]
> && suitC[2] == suitC[3] && suitC[3] == suitC[4] && suitC[4] ==
> suitC[5]) || (suitC[0] == suitC[2] && suitC[2] == suitC[3] && suitC[3]
> == suitC[4] && suitC[4] == suitC[6]) || (suitC[0] == suitC[2] &&
> suitC[2] == suitC[3] && suitC[3] == suitC[5] && suitC[5] == suitC[6])
> || (suitC[0] == suitC[2] && suitC[2] == suitC[4] && suitC[4] ==
> suitC[5] && suitC[5] == suitC[6]) || (suitC[0] == suitC[3] && suitC[3]
> == suitC[4] && suitC[4] == suitC[5] && suitC[5] == suitC[6]) ||
> (suitC[1] == suitC[2] && suitC[2] == suitC[3] && suitC[3] == suitC[4]
> && suitC[4] == suitC[5]) || (suitC[1] == suitC[2] && suitC[2] ==
> suitC[3] && suitC[3] == suitC[4] && suitC[4] == suitC[6]) || (suitC[1]
> == suitC[2] && suitC[2] == suitC[3] && suitC[3] == suitC[5] &&
> suitC[5] == suitC[6]) || (suitC[1] == suitC[2] && suitC[2] == suitC[4]
> && suitC[4] == suitC[5] && suitC[5] == suitC[6]) || (suitC[1] ==
> suitC[3] && suitC[3] == suitC[4] && suitC[4] == suitC[5] && suitC[5]
> == suitC[6]) || (suitC[2] == suitC[3] && suitC[3] == suitC[4] &&
> suitC[4] == suitC[5] && suitC[5] == suitC[6]))

That is impossible to maintain or understand. Surely there must be
better ways. :)

How about: devise a grading system for each hand and compare the
computed values of each hand. For example, add 100 points when there
is a pair, add 10000 when all four of a value is at hand, etc. Fine
tune it with the values of the cards like a pair of As is 100 + 13 and
a pair of Ks is 100 + 12, etc.

I don't know... Some way of grading a hand. :)

if (value_of(hand1) > value_of(hand2)) {
// hand 1 wins
}

Ali

Zeppe

10/20/2008 8:26:00 AM

0

Dear Danier,

few advices, not exhaustive, inline.


daniel.kaner@gmail.com wrote:
> 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:
>
> #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[7];
> int suitC[7];
> int rankC[7];
>
> 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[0] = ((rand() % 52) + 1);
> //cout << card[0] << endl;
> card[1] = ((rand() % 52) + 1);
> card[2] = ((rand() % 52) + 1);
> card[3] = ((rand() % 52) + 1);
> card[4] = ((rand() % 52) + 1);
> card[5] = ((rand() % 52) + 1);
> card[6] = ((rand() % 52) + 1);
> }while(card[0] == card[1] || card[0] == card[2] || card[0] ==
> card[3] || card[0] == card[4] || card[0] == card[5] || card[0] ==
> card[6] || card[1] == card[2] || card[1] == card[3] || card[1] ==
> card[4] || card[1] == card[5] || card[1] == card[6] || card[2] ==
> card[3] || card[2] == card[4] || card[2] == card[5] || card[2] ==
> card[6] || card[3] == card[4] || card[3] == card[5] || card[3] ==
> card[6] || card[4] == card[5] || card[4] == card[6] || card[5] ==
> card[6]);

This is ugly and inefficient. You want 52 cards to be shuffled and take
six of them, so you'd better shuffle numbers from 0 to 51 in a vector
and take the first six ones.

>
> //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[0] = (card[0] % 13);
> //cout << rank[0] << endl;
> rankC[1] = (card[1] % 13);
> //cout << rank[1] << endl;
> rankC[2] = (card[2] % 13);
> //cout << rank[2] << endl;
> rankC[3] = (card[3] % 13);
> //cout << rank[3] << endl;
> rankC[4] = (card[4] % 13);
> //cout << rank[4] << endl;
> rankC[5] = (card[5] % 13);
> //cout << rank[5] << endl;
> rankC[6] = (card[6] % 13);
> //cout << rank[6] << endl;

create a function to give you the rank of a card. Also, are you sure
this is the rank of a card?

>
> //4 suits - hearts, spades, shamrocks, diamonds
> suitC[0] = (rand() % 4);
> suitC[1] = (rand() % 4);
> suitC[2] = (rand() % 4);
> suitC[3] = (rand() % 4);
> suitC[4] = (rand() % 4);
> suitC[5] = (rand() % 4);
> suitC[6] = (rand() % 4);
>

once you have your cards, the suit is not random.


> /* 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;
> }*/
> }

if you enter a value out of bound, the program doesn't realise.


>
> if((suitC[0] == suitC[1] && suitC[1] == suitC[2] && suitC[2]
> == suitC[3] && suitC[3] == suitC[4]) || (suitC[0] == suitC[1] &&
> suitC[1] == suitC[2] && suitC[2] == suitC[3] && suitC[3] == suitC[5])
> || (suitC[0] == suitC[1] && suitC[1] == suitC[2] && suitC[2] ==
> suitC[3] && suitC[3] == suitC[6]) || (suitC[0] == suitC[1] && suitC[1]
> == suitC[2] && suitC[2] == suitC[4] && suitC[4] == suitC[5]) ||
> (suitC[0] == suitC[1] && suitC[1] == suitC[2] && suitC[2] == suitC[4]
> && suitC[4] == suitC[6]) || (suitC[0] == suitC[1] && suitC[1] ==
> suitC[2] && suitC[2] == suitC[5] && suitC[5] == suitC[6]) || (suitC[0]
> == suitC[1] && suitC[1] == suitC[3] && suitC[3] == suitC[4] &&
> suitC[4] == suitC[5]) || (suitC[0] == suitC[1] && suitC[1] == suitC[3]
> && suitC[3] == suitC[4] && suitC[4] == suitC[6]) || (suitC[0] ==
> suitC[1] && suitC[1] == suitC[3] && suitC[3] == suitC[5] && suitC[5]
> == suitC[6]) || (suitC[0] == suitC[1] && suitC[1] == suitC[4] &&
> suitC[4] == suitC[5] && suitC[5] == suitC[6]) || (suitC[0] == suitC[2]
> && suitC[2] == suitC[3] && suitC[3] == suitC[4] && suitC[4] ==
> suitC[5]) || (suitC[0] == suitC[2] && suitC[2] == suitC[3] && suitC[3]
> == suitC[4] && suitC[4] == suitC[6]) || (suitC[0] == suitC[2] &&
> suitC[2] == suitC[3] && suitC[3] == suitC[5] && suitC[5] == suitC[6])
> || (suitC[0] == suitC[2] && suitC[2] == suitC[4] && suitC[4] ==
> suitC[5] && suitC[5] == suitC[6]) || (suitC[0] == suitC[3] && suitC[3]
> == suitC[4] && suitC[4] == suitC[5] && suitC[5] == suitC[6]) ||
> (suitC[1] == suitC[2] && suitC[2] == suitC[3] && suitC[3] == suitC[4]
> && suitC[4] == suitC[5]) || (suitC[1] == suitC[2] && suitC[2] ==
> suitC[3] && suitC[3] == suitC[4] && suitC[4] == suitC[6]) || (suitC[1]
> == suitC[2] && suitC[2] == suitC[3] && suitC[3] == suitC[5] &&
> suitC[5] == suitC[6]) || (suitC[1] == suitC[2] && suitC[2] == suitC[4]
> && suitC[4] == suitC[5] && suitC[5] == suitC[6]) || (suitC[1] ==
> suitC[3] && suitC[3] == suitC[4] && suitC[4] == suitC[5] && suitC[5]
> == suitC[6]) || (suitC[2] == suitC[3] && suitC[3] == suitC[4] &&
> suitC[4] == suitC[5] && suitC[5] == suitC[6]))
> {

encapsulate different tests in to single functions (like
"isThreeOfAKind(...)") and think t better strategies to test single
conditions without enumerating all the possibilities.

Best wishes,

Zeppe

James Kanze

10/20/2008 8:42:00 AM

0

On Oct 20, 10:26 am, Zeppe
<ze...@remove.all.this.long.comment.yahoo.it> wrote:

> few advices, not exhaustive, inline.
> daniel.ka...@gmail.com wrote:
> This is ugly and inefficient. You want 52 cards to be shuffled
> and take six of them, so you'd better shuffle numbers from 0
> to 51 in a vector and take the first six ones.

That's the simplest and most general solution (since it allows
you to deal additional cards without any extra work, and most
closely simulates the real game.) Another alternative is to
fill the array, then choose one card from the first 52, put it
in the hand and swap it to the end, then choose the next from
the first 51, etc. Something like:

std::vector< int > deck( (boost::counting_iterator( 0 )),
(boost::counting_iterator( 52 )) ) ;
std::vector< int > hand ;
while ( hand.size() != cardsInHand ) {
std::size_t i = rand() % deck.size() ;
hand.push_back( deck[ i ] ) ;
std::swap( deck[ i ], *deck.end() - 1 ) ;
deck.pop_back() ;
}

(but random_shuffle is still simpler:

std::vector< int > deck( (boost::counting_iterator( 0 )),
(boost::counting_iterator( 52 )) ) ;
std::random_shuffle( deck.begin(), deck.end() ) ;
std::vector< int > result( deck.begin(), deck.begin() +
cardsInHand ) ;

Or even "hand.resize( cardsInHand )" and use deck as the hand.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Obnoxious User

10/20/2008 4:36:00 PM

0

On Sun, 19 Oct 2008 14:27:00 -0700, daniel.kaner wrote:

> On Oct 19, 5:10 pm, red floyd <no.spam.h...@example.com> wrote:
>> daniel.ka...@gmail.com wrote:
>> > 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.
>>
>> [redacted]
>>
>> No matter how many times you ask, we will *NOT* do your homework for
>> you.  Ask your instructor.
>>
>> See FAQ 5.2,
>>
>> http://www.parashift.com/c++-faq-lite/how-to-post.ht...
>
> Did I ask for answers? I asked you to please point me in the right
> direction. Thanks for the useless post.

You can simplify things drastically if you try to look at patterns.

Let a collector be a function that tries to collect a certain
type of poker hand from a finite set of cards.

Let "=" be an equality collector.
Let "+" be a straight collector.
Let ">" be a high card collector.
Let "?" be any card collector.

Let "S" be suit sensitive.
Let "*" be suit insensitive

The following poker hands can now be described with the
pattern (collector, number of cards, suit dependency) as:

Straight Flush +5S
Four of a Kind =4*
Full House =3* =2*
Flush ?5S
Straight +5*
Three of a Kind =3*
Two Pair =2* =2*
One Pair =2*
High Card >1*

All you need to do is provide a solution based on
that abstraction. Probably easiest to do with std::set<>
as a card container. I could publish the complete code,
but you only wanted the direction.

--
OU
Remember 18th of June 2008, Democracy died that afternoon.
http://frapedia.se/wiki/Information_...

James Kanze

10/20/2008 7:20:00 PM

0

Obnoxious User wrote:
> On Sun, 19 Oct 2008 14:27:00 -0700, daniel.kaner wrote:

> > On Oct 19, 5:10 pm, red floyd <no.spam.h...@example.com> wrote:
> >> daniel.ka...@gmail.com wrote:
> >> > 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.

> >> [redacted]

> >> No matter how many times you ask, we will *NOT* do your homework for
> >> you.  Ask your instructor.

> >> See FAQ 5.2,

> >> http://www.parashift.com/c++-faq-lite/how-to-post.ht...

> > Did I ask for answers? I asked you to please point me in the right
> > direction. Thanks for the useless post.

> You can simplify things drastically if you try to look at
> patterns.

You can also simplify greatly by choosing an appropriate
representation. A Card (a user defined type) has two
attributes, a suite and a value. Sort the cards by value, and
most of the checks for the different hands become fairly simple.
Straights were about the only thing which lead to an added
complication (because in a straight, an ace can be high or low).

Of course, if you're dealing with more than five cards, you need
to check all of the permuations of five cards this way.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34