我为我的 C++ 类编写了这个函数,我尝试了 x <= 4 并且也尝试了 x >= 4,但是当我跟踪它时,我没有看到它像应有的那样循环。它所做的是获取一个包含 5 个数字的数组并对它们进行排序,然后检查该组合是否构成满堂彩。
bool isFullHouse(int)
{
int match = 0;
BubbleSort(DiceHeld, 5);
for ( int x=0; x <= 4; x++ )
{
if (((DiceHeld[1] == x+1) && (DiceHeld[2] == x+1) && (DiceHeld[3] == x+2) && (DiceHeld[4] == x+2) && (DiceHeld[5] == x+2)) ||
((DiceHeld[1] == x+1) && (DiceHeld[2] == x+1) && (DiceHeld[3] == x+1) && (DiceHeld[4] == x+2) && (DiceHeld[5] == x+2)) ||
((DiceHeld[1] == x+1) && (DiceHeld[2] == x+1) && (DiceHeld[3] == x+3) && (DiceHeld[4] == x+3) && (DiceHeld[5] == x+3)) ||
((DiceHeld[1] == x+1) && (DiceHeld[2] == x+1) && (DiceHeld[3] == x+1) && (DiceHeld[4] == x+3) && (DiceHeld[5] == x+3)) ||
((DiceHeld[1] == x+1) && (DiceHeld[2] == x+1) && (DiceHeld[3] == x+4) && (DiceHeld[4] == x+4) && (DiceHeld[5] == x+4)) ||
((DiceHeld[1] == x+1) && (DiceHeld[2] == x+1) && (DiceHeld[3] == x+1) && (DiceHeld[4] == x+4) && (DiceHeld[5] == x+4)) ||
((DiceHeld[1] == x+1) && (DiceHeld[2] == x+1) && (DiceHeld[3] == x+5) && (DiceHeld[4] == x+5) && (DiceHeld[5] == x+5)) ||
((DiceHeld[1] == x+1) && (DiceHeld[2] == x+1) && (DiceHeld[3] == x+6) && (DiceHeld[4] == x+2) && (DiceHeld[5] == x+2)) ||
((DiceHeld[1] == x+1) && (DiceHeld[2] == x+1) && (DiceHeld[3] == x+6) && (DiceHeld[4] == x+6) && (DiceHeld[5] == x+6)) ||
((DiceHeld[1] == x+1) && (DiceHeld[2] == x+1) && (DiceHeld[3] == x+1) && (DiceHeld[4] == x+6) && (DiceHeld[5] == x+6)))
{
match = 1;
}
}
if (match == 1)
{
return true;
}
else
{
return false;
}
}