Added straight.
This commit is contained in:
@ -44,10 +44,10 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) {
|
||||
|
||||
// TESTING HAND
|
||||
winning.full[0] = CARD_CLUBS_ACE;
|
||||
winning.full[1] = CARD_CLUBS_TWO;
|
||||
winning.full[2] = CARD_CLUBS_FIVE;
|
||||
winning.full[3] = CARD_DIAMONDS_THREE;
|
||||
winning.full[4] = CARD_SPADES_TWO;
|
||||
winning.full[1] = CARD_SPADES_TWO;
|
||||
winning.full[2] = CARD_DIAMONDS_THREE;
|
||||
winning.full[3] = CARD_HEARTS_FOUR;
|
||||
winning.full[4] = CARD_SPADES_FIVE;
|
||||
winning.full[5] = CARD_CLUBS_QUEEN;
|
||||
winning.full[6] = CARD_CLUBS_JACK;
|
||||
|
||||
@ -64,7 +64,7 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) {
|
||||
|
||||
// Now look for the matching cards (Reverse order to order from A to 10)
|
||||
for(j = 1; j <= 4; j++) {
|
||||
l = card == CARD_FIVE && j == 4 ? CARD_ACE : number - j;//Ace low.
|
||||
l = number == CARD_FIVE && j == 4 ? CARD_ACE : number - j;//Ace low.
|
||||
index = cardContains(winning.full, winning.size, cardGet(l, suit));
|
||||
if(index == -1) break;
|
||||
winning.set[j] = index;
|
||||
@ -128,7 +128,6 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) {
|
||||
for(i = 0; i < winning.size; i++) {
|
||||
card = winning.full[i];
|
||||
suit = cardGetSuit(card);
|
||||
winning.set[0] = i;
|
||||
winning.count = 1;
|
||||
for(j = i+1; j < winning.size; j++) {
|
||||
if(cardGetSuit(winning.full[j]) != suit) continue;
|
||||
@ -137,13 +136,35 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) {
|
||||
if(winning.count == POKER_WINNING_SET_SIZE) break;
|
||||
}
|
||||
if(winning.count < POKER_WINNING_SET_SIZE) continue;
|
||||
winning.type = POKER_WINNING_TYPE_FOUR_OF_A_KIND;
|
||||
printf("Four of a kind\n");
|
||||
winning.set[0] = i;
|
||||
winning.type = POKER_WINNING_TYPE_FLUSH;
|
||||
printf("Flush\n");
|
||||
return winning;
|
||||
}
|
||||
|
||||
// Straight (sequence any suit)
|
||||
winning.count = 0;
|
||||
for(i = 0; i < winning.size; i++) {
|
||||
card = winning.full[i];
|
||||
number = cardGetNumber(card);
|
||||
if(number < CARD_FIVE) continue;
|
||||
winning.count = 1;
|
||||
|
||||
for(j = 1; j <= 4; j++) {
|
||||
l = number == CARD_FIVE && j == 4 ? CARD_ACE : number - j;//Ace low.
|
||||
index = cardContainsNumber(winning.full, winning.size, l);
|
||||
if(index == -1) break;
|
||||
winning.set[j] = index;
|
||||
winning.count++;
|
||||
}
|
||||
|
||||
// Check if has all necessary cards.
|
||||
if(winning.count < POKER_WINNING_SET_SIZE) continue;
|
||||
winning.set[0] = i;
|
||||
winning.type = POKER_WINNING_TYPE_STRAIGHT;
|
||||
printf("Flush\n");
|
||||
return winning;
|
||||
}
|
||||
|
||||
// Three of a kind
|
||||
winning.count = 0;
|
||||
|
@ -14,6 +14,8 @@
|
||||
#define POKER_WINNING_TYPE_STRAIGHT_FLUSH 0x02
|
||||
#define POKER_WINNING_TYPE_FOUR_OF_A_KIND 0x03
|
||||
#define POKER_WINNING_TYPE_FULL_HOUSE 0x04
|
||||
#define POKER_WINNING_TYPE_FLUSH 0x06
|
||||
#define POKER_WINNING_TYPE_STRAIGHT 0x06
|
||||
|
||||
#define POKER_WINNING_SET_SIZE 5
|
||||
|
||||
|
Reference in New Issue
Block a user