0

I want to ask a function to check Full House combination in Poker.
So far i have this code :

for (a=0 ; a<2 ; a++)
{
    for (b=a+1 ; b<7 ; b++)
    {
        if (pValue[a] == pValue[b])
        {
            pair++;
            for (c=b+1 ; c<7 ; c++)
            {
                if (pValue[b] == pValue[c])
                {
                    thrice++;
                }
            }
        }
    }
}

So i checking :

if (pair >= 1 && thrice >= 2 || pair >=2 && thrice >= 1)
{
    nameComb = "Full House";
}

But if i have 3 cards with same value, the result is pair = 2 and thrice = 1
So when the Full House condition will met.
How can i check if pair is the same value with thrice ?

hotarufire
  • 23
  • 2
  • If your pair is the same value as your set of three, check you deck. This triple-nested loop monster will always be hard to understand and debug. For evaluating poker hands, I recommend first sorting the cards by rank. Then all the future tests become much simpler. And apply the tests from highest hands down: i.e., look for straight flushes, then quads, etc. – Lee Daniel Crocker Feb 23 '15 at 17:01

1 Answers1

0

Try my code:

var pValue:Array = [1,1,1,2,2];

var values:Array = [];
var counts:Array = [];
var index:int;

for (var i:int = 0; i < pValue.length; i++)
{
    if ((index = values.indexOf(pValue[i])) == -1)
    {
        values.push(pValue[i]);
        counts.push(1);
    }
    else
    {
        counts[index]++;
    }
}

trace(values);
trace(counts);

if (counts.length == 2 && ((counts[0] == 3 && counts[1] == 2) || (counts[0] == 2 && counts[1] == 3)))
{
    trace("Full House");
}
Daniil Subbotin
  • 6,138
  • 5
  • 20
  • 24