public KeyT(int handSize, int maxHandSize, CardSet cards) { HandSize = (byte)handSize; RankCards = NormRank.Convert(cards); FlushCards = ExtractFlush(cards, maxHandSize); if (handSize < 5) { return; } HandValue = CardSetEvaluator.Evaluate(ref cards); }
void OnTestCombin(CardSet cards, int[] cardIndexes, int linkValue) { UInt32 handValue = (UInt32)linkValue; UInt32 expHandValue = CardSetEvaluator.Evaluate(ref cards); if (handValue != expHandValue) { string cardsText = StdDeck.Descriptor.GetCardNames(cardIndexes); // Set a breakpoint here to see what went wrong. } int handType = handValue == 0 ? 0 : (int)HandValue.GetKind(handValue) + 1; _typeCounts[handType]++; }
void OnCombinLinkStates(CardSet srcCards, int count) { // Find the state for theses cards. No search is necessary here, // as the cards are dealt in the same order as in creation, we can use _combinCount. int srcMapIdx = _combinCount; Debug.Assert(_cardsToState[count][srcMapIdx].Cards == srcCards); State srcState = _states[_cardsToState[count][srcMapIdx].StateId]; // Deal next cards. for (int c = 0; c < 52; ++c) { if (srcState.Table[c] != 0) { // Already linked continue; } CardSet newCard = StdDeck.Descriptor.CardSets[c]; if (newCard.IsIntersectingWith(srcCards)) { // Impossible card. continue; } CardSet dstCards = newCard | srcCards; int linkValue; if (count + 1 < _maxHandSize) { // Link to state int dstMapIdx = Array.BinarySearch(_cardsToState[count + 1], new CardsToState { Cards = dstCards }); Debug.Assert(_cardsToState[count + 1][dstMapIdx].Cards == dstCards); State dstState = _states[_cardsToState[count + 1][dstMapIdx].StateId]; linkValue = dstState.Id; } else { // Link to hand value. linkValue = (int)CardSetEvaluator.Evaluate(ref dstCards); } srcState.Table[c] = linkValue; } _combinCount++; }
private void FillFinalHands(State state, CardSet cards) { for (int c = 0; c < 52; ++c) { if (state.Table[c] != 0) { // Already done. continue; } CardSet nextCard = StdDeck.Descriptor.CardSets[c]; if (nextCard.IsIntersectingWith(cards)) { continue; } CardSet finalHand = cards | nextCard; Debug.Assert(finalHand.CountCards() == _maxHandSize); UInt32 handRank = CardSetEvaluator.Evaluate(ref finalHand); state.Table[c] = (Int32)handRank; } }