Просмотреть всю тему "Самое быстрое определение покерной комбинации — Часть 2" »»
Re: Самое быстрое определение покерной комбинации — Часть 2   ID:25274   ответ на 25243 Вт, 20 ноября 2007 09:25 [#]
Kielbasa Форумы CasinoGames
Если я правильно понимаю, то всё уже украдено до нас:

<div style="margin:20px; margin-top:5px">
<div class="smallfont" style="margin-bottom:2px">Код:</div>
<pre class="alt2" dir="ltr" style="
margin: 0px;
padding: 4px;
border: 1px inset;
width: 640px;
height: 498px;
text-align: left;
overflow: auto"> void Combination::Parse(__int64 cards)
{
unsigned int four_mask, three_mask, two_mask;
value_ = 0;
const unsigned int sd = (unsigned short int)cards;
const unsigned int ss = *((unsigned short int *)(&cards)+1);
const unsigned int sh = *((unsigned short int *)(&cards)+2);
const unsigned int sc = *((unsigned short int *)(&cards)+3);
const unsigned int ranks = (sc | sd | sh | ss);// & 0xFFF;
const unsigned int n_ranks = nBitsTable[ranks];
const unsigned int n_dups = ((unsigned int)(7 - n_ranks));

if (n_ranks >= 5)
{
if (nBitsTable[ss] >= 5)
{
if (straightTable[ss] != 0)
{
value_ = HANDTYPE_VALUE_STRAIGHTFLUSH + (unsigned int)(straightTable[ss] << TOP_CARD_SHIFT);
return;
}
else
value_ = HANDTYPE_VALUE_FLUSH + topFiveCardsTable[ss];
}
else if (nBitsTable[sc] >= 5)
{
if (straightTable[sc] != 0)
{
value_ = HANDTYPE_VALUE_STRAIGHTFLUSH + (unsigned int)(straightTable[sc] << TOP_CARD_SHIFT);
return;
}
else
value_ = HANDTYPE_VALUE_FLUSH + topFiveCardsTable[sc];
}
else if (nBitsTable[sd] >= 5)
{
if (straightTable[sd] != 0)
{
value_ = HANDTYPE_VALUE_STRAIGHTFLUSH + (unsigned int)(straightTable[sd] << TOP_CARD_SHIFT);
return;
}
else
value_ = HANDTYPE_VALUE_FLUSH + topFiveCardsTable[sd];
}
else if (nBitsTable[sh] >= 5)
{
if (straightTable[sh] != 0)
{
value_ = HANDTYPE_VALUE_STRAIGHTFLUSH + (unsigned int)(straightTable[sh] << TOP_CARD_SHIFT);
return;
}
else
value_ = HANDTYPE_VALUE_FLUSH + topFiveCardsTable[sh];
}
else
{
unsigned int st = straightTable[ranks];
if (st != 0)
value_ = HANDTYPE_VALUE_STRAIGHT + (st << TOP_CARD_SHIFT);
}

/*
Another win — if there can't be a FH/Quads (n_dups < 3),
which is true most of the time when there is a made mask, then if we've
found a five card mask, just return. This skips the whole process of
computing two_mask/three_mask/etc.
*/
if (value_ != 0 && n_dups < 3)
return;// retval;
}
switch (n_dups)
{
case 0:
/* It's a no-pair mask */
value_ = HANDTYPE_VALUE_HIGHCARD + topFiveCardsTable[ranks]; return;
case 1:
{
two_mask = ranks ^ (sc ^ sd ^ sh ^ ss);
value_ = (unsigned int) (HANDTYPE_VALUE_PAIR + (topCardTable[two_mask] << TOP_CARD_SHIFT));
unsigned int t = ranks ^ two_mask; /* Only one bit set in two_mask */
unsigned int kickers = (topFiveCardsTable[t] >> 4) & ~FIFTH_CARD_MASK;
value_ += kickers;
return;// retval;
}

case 2:
/* Either two pair or trips */
two_mask = ranks ^ (sc ^ sd ^ sh ^ ss);
if (two_mask != 0)
{
unsigned int t = ranks ^ two_mask; /* Exactly two bits set in two_mask */
value_ = (unsigned int) (HANDTYPE_VALUE_TWOPAIR + (topFiveCardsTable[two_mask] & (TOP_CARD_MASK | SECOND_CARD_MASK))
+ (topCardTable[t] << THIRD_CARD_SHIFT));

return;// retval;
}
else
{
//unsigned int t, second;
three_mask = ((sc & sd) | (sh & ss)) & ((sc & sh) | (sd & ss));
value_ = (unsigned int) (HANDTYPE_VALUE_TRIPS + (topCardTable[three_mask] << TOP_CARD_SHIFT));
unsigned int t = ranks ^ three_mask; /* Only one bit set in three_mask */
unsigned int second = topCardTable[t];
value_ += (second << SECOND_CARD_SHIFT);
t ^= (1U << (int)second);
value_ += (unsigned int) (topCardTable[t] << THIRD_CARD_SHIFT);
return;// retval;
}

default:
/* Possible quads, fullhouse, straight or flush, or two pair */
four_mask = sh & sd & sc & ss;
if (four_mask != 0)
{
unsigned int tc = topCardTable[four_mask];
value_ = (unsigned int) (HANDTYPE_VALUE_FOUR_OF_A_KIND + (tc << TOP_CARD_SHIFT)
+ ((topCardTable[ranks ^ (1U << (int)tc)]) << SECOND_CARD_SHIFT));
return;// retval;
}
two_mask = ranks ^ (sc ^ sd ^ sh ^ ss);
if (nBitsTable[two_mask] != n_dups)
{
//unsigned int tc, t;
three_mask = ((sc & sd) | (sh & ss)) & ((sc & sh) | (sd & ss));
//value_ = HANDTYPE_VALUE_FULLHOUSE;
unsigned int tc = topCardTable[three_mask];
value_ += HANDTYPE_VALUE_FULLHOUSE + (tc << TOP_CARD_SHIFT);
unsigned int t = (two_mask | three_mask) ^ (1U << (int)tc);
value_ += (unsigned int) (topCardTable[t] << SECOND_CARD_SHIFT);
return;// retval;
}

//if (value_ != 0) /* flush and straight */
// return;// retval;
//else
if(value_ == 0)
{
/* Must be two pair */
//unsigned int top, second;

//value_ = HANDTYPE_VALUE_TWOPAIR;
unsigned int top = topCardTable[two_mask];
value_ = HANDTYPE_VALUE_TWOPAIR + (top << TOP_CARD_SHIFT);
unsigned int second = topCardTable[two_mask ^ (1 << (int)top)];
value_ += (second << SECOND_CARD_SHIFT);
value_ += (unsigned int) ((topCardTable[ranks ^ (1U << (int)top) ^ (1 << (int)second)]) << THIRD_CARD_SHIFT);
return;// retval;
}
}
}</pre>
</div>Я это использовал для самопального покерстова %), но пришёл к выводу, что сравнивать "в лоб" бесперспективно, и теперь сооружаю совершенно другой алгоритм.