2

I want to check for a straight combination in a poker game.

So, I have this array: var tempArr:Array = new Array;

I have this for sorting the array:

for (i = 0; i < 7; i++)
{
    tempArr[i] = pValue[i];
}
tempArr.sort( Array.NUMERIC );

pValue is the value of the cards, it's have range from 2 to 14.

So, if I have this Array: tempArray = [2,3,3,4,5,5,6];

How can I check if I have a straight combination in my hand?

hotarufire
  • 23
  • 2

1 Answers1

0

Set a bucket array to save if you got a card in hand

var t:Array = [];
//t[2] = 1;mean you have 2
// t[3] = 0;mean you don't have 3

//first initialize t
for(var i:int = 0; i < 15; i++)
{ 
   t[i] = 0;
}

//then set the values from  tempArray
for (var j:int = 0; j < tempArray.length; j++)
{
   t[tempArray[j]] = 1;
}

//if you have a straight combination in your hand
//you will get a k that t[k] & t[k-1]& t[k-2] & t[k-3] & t[k-4] == 1

var existed:boolean = false;//the flag save if you got a straight combination

for (var k:int = t.length - 1; k >= 4; k--)
{

    if (t[k] == 0)
    {
        continue;
    }

    if ((t[k] & t[k-1] & t[k-2] & t[k-3] & t[k-4]) == 1)
    {
         existed = true;
         break;
    }
}
Pan
  • 2,101
  • 3
  • 13
  • 17