bool CGameLogic::IsAllLine(BYTE cbCard[], BYTE cbCount, bool bSameColor)
{
if (cbCount == 0) return true;
if (cbCount != 3 && cbCount != 5 && cbCount != 8 && cbCount != 10 && cbCount != 13)
{
return false;
}
if (cbCount == 3 || cbCount == 5)
{
return IsLine(cbCard, cbCount, bSameColor);
}
BYTE cbTemp[13];
memset(cbTemp, 0, sizeof(cbTemp));
for (BYTE i = 0; i < cbCount; i++)
{
cbTemp[i] = cbCard[i];
}
BYTE cbIndex[5] = { 0,1,2,3,4 };
do
{
BYTE cbCarResult[5];
for(BYTE i=0;i<5;++i)
{
cbCarResult[i]=cbTemp[cbIndex[i]];
cbTemp[cbIndex[i]]=0;
}
SortCardByValue(cbTemp,cbCount);
if (IsLine(cbCarResult, 5, bSameColor) && IsAllLine(cbTemp, cbCount - 5, bSameColor))
{
BYTE cbSortCount = 0;
for (BYTE i = 0; i < 5; i++)
{
cbCard[cbSortCount++] = cbCarResult[i];
}
for (BYTE i = 0; i < cbCount - 5; i++)
{
cbCard[cbSortCount++] = cbTemp[i];
}
return true;
}
else
{
for (BYTE i = 0; i < cbCount; i++)
{
cbTemp[i] = cbCard[i];
}
}
if (cbIndex[4] == (cbCount - 1))
{
BYTE i = 4;
for (; i > 0; i--)
{
if ((cbIndex[i - 1] + 1) != cbIndex[i])
{
BYTE cbNewIndex = cbIndex[i - 1];
for (BYTE j = (i - 1); j < 5; j++) cbIndex[j] = cbNewIndex + j - (i - 1) + 1;
break;
}
}
if (i == 0) break;
}
else cbIndex[4]++;
} while (true);
return false;
}
{
if (cbCount == 0) return true;
if (cbCount != 3 && cbCount != 5 && cbCount != 8 && cbCount != 10 && cbCount != 13)
{
return false;
}
if (cbCount == 3 || cbCount == 5)
{
return IsLine(cbCard, cbCount, bSameColor);
}
BYTE cbTemp[13];
memset(cbTemp, 0, sizeof(cbTemp));
for (BYTE i = 0; i < cbCount; i++)
{
cbTemp[i] = cbCard[i];
}
BYTE cbIndex[5] = { 0,1,2,3,4 };
do
{
BYTE cbCarResult[5];
for(BYTE i=0;i<5;++i)
{
cbCarResult[i]=cbTemp[cbIndex[i]];
cbTemp[cbIndex[i]]=0;
}
SortCardByValue(cbTemp,cbCount);
if (IsLine(cbCarResult, 5, bSameColor) && IsAllLine(cbTemp, cbCount - 5, bSameColor))
{
BYTE cbSortCount = 0;
for (BYTE i = 0; i < 5; i++)
{
cbCard[cbSortCount++] = cbCarResult[i];
}
for (BYTE i = 0; i < cbCount - 5; i++)
{
cbCard[cbSortCount++] = cbTemp[i];
}
return true;
}
else
{
for (BYTE i = 0; i < cbCount; i++)
{
cbTemp[i] = cbCard[i];
}
}
if (cbIndex[4] == (cbCount - 1))
{
BYTE i = 4;
for (; i > 0; i--)
{
if ((cbIndex[i - 1] + 1) != cbIndex[i])
{
BYTE cbNewIndex = cbIndex[i - 1];
for (BYTE j = (i - 1); j < 5; j++) cbIndex[j] = cbNewIndex + j - (i - 1) + 1;
break;
}
}
if (i == 0) break;
}
else cbIndex[4]++;
} while (true);
return false;
}