Quote:Original post by Danikar
Yeah if u want to send that to me that would be cool. I always like looking over other peoples code.
I PM'd it to ya. hope it helps.
Quote:Original post by Danikar
Yeah if u want to send that to me that would be cool. I always like looking over other peoples code.
Quote:Original post by Lothia
Tan that confuses the hell out of me. How does that prove they are flush if 5 is the highest? Could it not be you have, Ace, ace, Queen, Jack, and 10. And that 10 would make it a 5. Or maybe i just get the concept. It seems that you are doing a check high and low, but the low is really the high (ace) and ur high is really your low (two) Maybe it's the enum.. I have never heard of it.
enum rank_t{ RANK_TWO, RANK_THREE, RANK_FOUR, RANK_FIVE, RANK_SIX, RANK_SEVEN, RANK_EIGHT, RANK_NINE, RANK_TEN, RANK_JACK, RANK_QUEEN, RANK_KING, RANK_ACE, RANK_COUNT, RANK_FIRST=RANK_TWO};enum suit_t{ SUIT_CLUBS, SUIT_HEARTS, SUIT_SPADES, SUIT_DIAMONDS, SUIT_COUNT, SUIT_FIRST=SUIT_CLUBS};enum handvalue_t{ HANDVALUE_INVALID, HANDVALUE_JUNK, HANDVALUE_ONEPAIR, HANDVALUE_ONEPAIRJACKSORBETTER, HANDVALUE_TWOPAIR, HANDVALUE_THREEOFAKIND, HANDVALUE_STRAIGHT, HANDVALUE_FLUSH, HANDVALUE_FULLHOUSE, HANDVALUE_FOUROFAKIND, HANDVALUE_STRAIGHTFLUSH, HANDVALUE_ROYALFLUSH,};enum{ HAND_CARDCOUNT = 5};struct card_t{ rank_t rank; suit_t suit;};struct hand_t{ card_t cards[HAND_CARDCOUNT];};handvalue_t getHandValue(const hand_t& theHand){ handvalue_t result=HANDVALUE_INVALID; int cardRanks[RANK_COUNT]={0}; int cardSuits[SUIT_COUNT]={0}; rank_t rankHigh=RANK_TWO; rank_t rankLow=RANK_ACE; int validCards=0; for(int cardIndex=0;cardIndex<HAND_CARDCOUNT;++cardIndex) { bool cardIsValid=false; if((theHand.cards[cardIndex].rank<RANK_COUNT)&&(theHand.cards[cardIndex].suit<SUIT_COUNT)) { bool foundDuplicate=false; for(int otherCardIndex=cardIndex+1;otherCardIndex<HAND_CARDCOUNT;++otherCardIndex) { if((theHand.cards[cardIndex].rank==theHand.cards[otherCardIndex].rank)&&(theHand.cards[cardIndex].suit==theHand.cards[otherCardIndex].suit)) { foundDuplicate=true; } if(!foundDuplicate) { cardIsValid=true; } } } if(cardIsValid) { validCards++; cardRanks[theHand.cards[cardIndex].rank]++; cardSuits[theHand.cards[cardIndex].suit]++; if(theHand.cards[cardIndex].rank>rankHigh) { rankHigh=theHand.cards[cardIndex].rank; } if(theHand.cards[cardIndex].rank<rankLow) { rankLow=theHand.cards[cardIndex].rank; } } } if(HAND_CARDCOUNT==validCards) { for(int suitIndex=SUIT_FIRST;(result==HANDVALUE_INVALID)&&(suitIndex<SUIT_COUNT);++suitIndex) { if(HAND_CARDCOUNT==cardSuits[suitIndex]) { result=HANDVALUE_FLUSH; } } if(HANDVALUE_FLUSH==result) { if((HAND_CARDCOUNT-1)==(rankHigh-rankLow)) { if(cardRanks[RANK_ACE]) { result=HANDVALUE_ROYALFLUSH; } else { result=HANDVALUE_STRAIGHTFLUSH; } } else if(cardRanks[RANK_TWO]&&cardRanks[RANK_THREE]&&cardRanks[RANK_FOUR]&&cardRanks[RANK_FIVE]&&cardRanks[RANK_ACE]) { result=HANDVALUE_STRAIGHTFLUSH; } } else { bool fourOfAKind=false; bool threeOfAKind=false; int pairCount=0; bool jacksOrBetter=false; for(int rankIndex=0;(!fourOfAKind)&&(rankIndex<RANK_COUNT);++rankIndex) { switch(cardRanks[rankIndex]) { case 4: { fourOfAKind=true; }break; case 3: { threeOfAKind=true; }break; case 2: { pairCount++; if(rankIndex>=RANK_JACK) { jacksOrBetter=true; } }break; } } if(fourOfAKind) { result=HANDVALUE_FOUROFAKIND; } else if(threeOfAKind) { if(pairCount) { result=HANDVALUE_FULLHOUSE; } else { result=HANDVALUE_THREEOFAKIND; } } else { switch(pairCount) { case 2: { result=HANDVALUE_TWOPAIR; }break; case 1: { if(jacksOrBetter) { result=HANDVALUE_ONEPAIRJACKSORBETTER; } else { result=HANDVALUE_ONEPAIR; } }break; case 0: { if((HAND_CARDCOUNT-1)==(rankHigh-rankLow)) { result=HANDVALUE_STRAIGHT; } else if(cardRanks[RANK_TWO]&&cardRanks[RANK_THREE]&&cardRanks[RANK_FOUR]&&cardRanks[RANK_FIVE]&&cardRanks[RANK_ACE]) { result=HANDVALUE_STRAIGHT; } else { result=HANDVALUE_JUNK; } }break; } } } } return(result);}
Quote:Original post by Lothia
Can you explain what a enum is? It seems to me its a struct.