English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

#include
#include
#include
#include
#include
#include


using namespace std;
using std::cout;
using std::strcmp;

//int random;

int main()
{
srand((unsigned)time(0));


string general[52] = {"Ah","2h","3h","4h","5h","6h","7h","8h","9h","10h","Jh","Qh","Kh","Ac","2c","3c","4c","5c","6c","7c","8c","9c","10c","Jc","Qc","Kc",
"As","2s","3s","4s","5s","6s","7s","8s","9s","10s","Js","Qs","Ks","Ad","2d","3d","4d","5d","6d","7d","8d","9d","10d","Jd","Qd","Kd"};



int generalnumber[]={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}; //shuffled array
int id1, id2;
int temp;
for (int i = 0; i <=300; i++ )
{
id1 = rand()%52;
id2 = rand()%52;
if(id1!=id2)
{

temp = generalnumber[id2];
generalnumber[id2] = gene

2007-03-17 08:16:59 · 2 answers · asked by Jayu P 1 in Computers & Internet Programming & Design

2 answers

You will need to determine the hands programatically from best hand to worst hand.

string cards[5]; // use 7 for hold'em type games
string description; // hand description

void determinehand()
{
//sort hand in order from A to 2
if( cards[0][0]=='A' && cards1][0]=='K' &&...&& v[4][0]='T')
if(cards[0][1]==cards[1][1]==...==cards[4][1])
cards.description = "Royal Flush"
else
cards.descirption="Straight Flush"
else
... determine other hands
}

int comparehands(hand1,hand2)
{
// will compare the which hand is higher
}

I would guess that you are looking at a couple hundred lines of code. Use some loops for a lot of the determinations

2007-03-17 09:17:17 · answer #1 · answered by Math Guy 4 · 0 0

Assume you have MyHand[4] as the cards you have, elements 0-4 each have a card, I'd write a function that determines the best hand you have. In it, I'd parse the various pieces - I'm writing psuedo code here because I don't have a c++ compiler handy (that and I'm too used to C# now, heh)

BestHand()
{
bool isStraight = IsStraight(MyHand);
bool isFlush = IsFlush(MyHand);

if(isFlush && isStraight)
return "IsStraightFlush" //probably use enums for return type

if(isFlush)
return "IsFlush"

if(isStraight)
return "IsStraight"

bool 4ofAkind = Is4ofaKind(MyHand)
return "is4ofaKind"
bool 3ofAkind = Is3ofaKind(MyHand)
bool 2pair = is2Pair(MyHand)
bool pair = isPair(MyHand)

if(3ofaKind && pair)
return "FullHouse"

if(3ofaKind)
return "3ofaKind"

if(2pair)
return "2pair"

if(pair)
return "pair"



That's a rough outline. There's probably room for the design to be cleaner. If you're comparing Hand1 to Hand2, you'd have to incorporate card ranking - ie straight flush with Ace high is better than straight flush with K high.

If that's your goal, I'd probably write a scoring system. You definitely don't want to write something that says... AAAKK is best full house, AAAQQ is 2nd best full house. That would be a ton of horrible code. An elegant scoring system could be put together in less than 100 lines of code easily.

For example, Straight Flush is worth 1,000,000 + the high card * 1000 (J=11, Q=12, K=13, A=14)
so St.Flush A high = 1,001,400points.
St.flush K high = 1,001,300.

Full House would be worht 900,000 + 3ofAkindcard * 1000 + pairCard * 100

Flush would be worth 800,000 + top card *10000 + 2nd card * 1000 + 3rd card * 100 + 4th card * 10 + 5th card * 1

Straight would be worth 800,000 + top card * 1000

etc...
basically you have to come up with a scoring method that lets you call the function and get score, then you can quickly compare the score. you just have to be sure that the scoring algorithm you use is smart enough that a flush never beats a full house (and I haven't checked to make sure what I recommended actually does that)

Doing something like that would let you write something that compare 10 hands easily.

Anyhoo... good luck with whatever you're up to :)

2007-03-17 09:18:06 · answer #2 · answered by vbslinger 2 · 0 0

fedest.com, questions and answers