Esempio n. 1
0
        public void GeneratedStandardDeckCardMaskTableShouldMatchActualOne()
        {
            var deck = new StandardDeck();

            var standardTable = DeckTablesHelper.GenerateStandardDeckCardMaskTable();

            for (var cardIndex = 0; cardIndex != deck.NoOfCards; ++cardIndex)
            {
                var generatedValue = standardTable[cardIndex];
                var actualValue = StandardDeck.CardMaskTable[cardIndex];
                Assert.AreEqual(generatedValue, actualValue);
            }
        }
Esempio n. 2
0
        private static int GetStraightRankMask(int ranks)
        {
            var ranks1 = ranks & (ranks << 1);
            var ranks2 = ranks1 & (ranks << 2);
            var ranks3 = ranks2 & (ranks << 3);
            var ranks4 = ranks3 & (ranks << 4);

            if (ranks1 != 0 && ranks2 != 0 && ranks3 != 0 && ranks4 != 0)
            {
                var rankMask = GetTopCardRankMask(ranks4);
                return rankMask;
            }

            var deck = new StandardDeck();
            var aceRankIndex = deck.ToRankIndex(CardRank.Ace);
            var twoRankIndex = deck.ToRankIndex(CardRank.Two);
            var threeRankIndex = deck.ToRankIndex(CardRank.Three);
            var fourRankIndex = deck.ToRankIndex(CardRank.Four);
            var fiveRankIndex = deck.ToRankIndex(CardRank.Five);
            var standardRulesFiveStraight = (1 << aceRankIndex) | (1 << twoRankIndex) | (1 << threeRankIndex) |
                (1 << fourRankIndex) | (1 << fiveRankIndex);

            return (ranks & standardRulesFiveStraight) == standardRulesFiveStraight
                ? deck.ToRankIndex(CardRank.Five)
                : 0;
        }