我想问一个在扑克中检查全屋组合的功能。
到目前为止,我有以下代码:
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++;
}
}
}
}
}
所以我检查了一下:
if (pair >= 1 && thrice >= 2 || pair >=2 && thrice >= 1)
{
nameComb = "Full House";
}
但是如果我有3张具有相同值的卡片,结果是pair = 2
和thrice = 1
所以什么时候才能满足众议院的全部条件。
如何检查pair与thrice的值是否相同?
发布于 2015-02-21 20:55:33
试试我的代码:
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");
}
https://stackoverflow.com/questions/28645910
复制相似问题