Example #1
0
        public void SameCardsAreEqual()
        {
            ICard cardOne = texasHoldEmBuilder.CreateNewCard(CardValue.Eight, CardSuit.Diamond);
            ICard cardTwo = texasHoldEmBuilder.CreateNewCard(CardValue.Eight, CardSuit.Diamond);

            Assert.IsTrue(cardOne.Equals(cardTwo));
        }
Example #2
0
 public static bool IsEqual(ICard card1, ICard card2)
 {
     if (card1 == null)
     {
         return(card2 == null);
     }
     return(card1.Equals(card2));
 }
Example #3
0
        public void EqualsFunctionAndDoubleEquals_AllAreEquivilant()
        {
            var blackJackCard = new BlackJackCard(AceOfSpades, FaceDown);

            Assert.IsFalse(AceOfSpades.Equals(BlackJackAceOfSpades));

            Assert.IsTrue(blackJackCard.Equals(BlackJackAceOfSpades));
            Assert.IsTrue(blackJackCard == BlackJackAceOfSpades);
        }
        public void create_and_returns_new_randomcard()
        {
            Dependencies.randomInstance.ConstantValue = new Random(13);

            ICard randomCard1 = Deck.GenerateRandomCard();
            ICard randomCard2 = Deck.GenerateRandomCard();
            ICard randomCard3 = Deck.GenerateRandomCard();
            ICard randomCard4 = Deck.GenerateRandomCard();

            Assert.IsTrue(randomCard1.Equals(new Card(Suit.Hearts, Rank.Nine)));
            Assert.IsTrue(randomCard2.Equals(new Card(Suit.Spades, Rank.Five)));
            Assert.IsTrue(randomCard3.Equals(new Card(Suit.Clubs, Rank.Queen)));
            Assert.IsTrue(randomCard4.Equals(new Card(Suit.Hearts, Rank.King)));
            Dependencies.randomInstance.reset();
        }
        /// <summary>
        /// The InnerAdd.
        /// </summary>
        /// <param name="value">The value<see cref="V"/>.</param>
        /// <returns>The <see cref="bool"/>.</returns>
        protected override bool InnerAdd(V value)
        {
            ulong key = unique.Key(value, value.UniqueSeed);
            // get position index in table, which is an absolute value from key %(modulo) size. Simply it is rest from dividing key by size
            ulong pos = getPosition(key);

            ICard <V> card = table[pos];

            // add in case when item doesn't exist and there is no conflict
            if (card == null)
            {
                table[pos] = createNew(key, value);
                countIncrement();
                return(true);
            }

            // loop over conflicts assigned as reference in extent field
            for (; ;)
            {
                /// key check
                if (card.Equals(key))
                {
                    /// when card was removed decrese counter
                    if (card.Removed)
                    {
                        /// update card have same key with new value
                        card.Removed = false;
                        card.Value   = value;
                        removedDecrement();
                        return(true);
                    }
                    return(false);
                }
                /// check that all conflicts was examinated and local card is the last one
                if (card.Extent == null)
                {
                    /// assign new card as extent reference and increase conflicts
                    card.Extent = createNew(key, value);
                    conflictIncrement();
                    return(true);
                }
                /// assign next conflict card to local card
                card = card.Extent;
            }
        }
        public void peekcard_returns_right_card_from_sorted_deck()
        {
            // sorted by Suit, then Rank
            IDeck d = new Deck();

            d.Sort();
            int index = 0;

            foreach (Suit suit in Enum.GetValues(typeof(Suit)))
            {
                foreach (Rank rank in Enum.GetValues(typeof(Rank)))
                {
                    index = (int)suit * 13 + (int)rank;
                    ICard card = d.PeekCard(index);
                    Assert.IsTrue(card.Equals(new Card(suit, rank)));
                }
            }
        }
        /// <summary>
        /// The InnerPut.
        /// </summary>
        /// <param name="value">The value<see cref="V"/>.</param>
        /// <returns>The <see cref="ICard{V}"/>.</returns>
        protected override ICard <V> InnerPut(V value)
        {
            ulong     key  = unique.Key(value, value.UniqueSeed);
            ulong     pos  = getPosition(key);
            ICard <V> card = table[pos]; /// local for last removed item finded

            // add in case when item doesn't exist and there is no conflict
            if (card == null)
            {
                card       = createNew(key, value);
                table[pos] = card;
                countIncrement();
                return(card);
            }

            // loop over conflicts assigned as reference in extent field
            for (; ;)
            {
                /// key check
                if (card.Equals(key))
                {
                    /// when card was removed decrese counter
                    card.Value = value;
                    if (card.Removed)
                    {
                        card.Removed = false;
                        removedDecrement();
                    }
                    /// update card have same key with new value

                    return(card);
                }
                /// check that all conflicts was examinated and local card is the last one
                if (card.Extent == null)
                {
                    var newcard = createNew(key, value);
                    card.Extent = newcard;
                    conflictIncrement();
                    return(newcard);
                }
                /// assign next conflict card to local card
                card = card.Extent;
            }
        }
        /// <summary>
        /// The InnerPut.
        /// </summary>
        /// <param name="value">The value<see cref="ICard{V}"/>.</param>
        /// <returns>The <see cref="ICard{V}"/>.</returns>
        protected override ICard <V> InnerPut(ICard <V> value)
        {
            ulong key = value.Key;
            // get position index in table, which is an absolute value from key %(modulo) size. Simply it is rest from dividing key and size
            ulong pos = getPosition(key);

            ICard <V> card = table[pos]; /// local for last removed item finded

            // add in case when item doesn't exist and there is no conflict
            if (card == null)
            {
                card       = createNew(value);
                table[pos] = card;
                countIncrement();
                return(card);
            }

            // loop over conflicts assigned as reference in extent field
            for (; ;)
            {
                /// key check
                if (card.Equals(key))
                {
                    /// update card have same key with new value
                    card.Value = value.Value;
                    /// when card was removed decrese counter
                    if (card.Removed)
                    {
                        card.Removed = false;
                        removedDecrement();
                    }
                    return(card);
                }
                /// check that all conflicts was examinated and local card is the last one
                if (card.Extent == null)
                {
                    var newcard = createNew(value);
                    card.Extent = newcard;
                    conflictIncrement();
                    return(newcard);
                }
                card = card.Extent;
            }
        }
        /// <summary>
        /// The InnerPut.
        /// </summary>
        /// <param name="key">The key<see cref="ulong"/>.</param>
        /// <param name="value">The value<see cref="V"/>.</param>
        /// <returns>The <see cref="ICard{V}"/>.</returns>
        protected override ICard <V> InnerPut(ulong key, V value)
        {
            // get position index in table using own native alghoritm - submix
            ulong pos = getPosition(key);

            ICard <V> card = table[pos]; // get item by position

            // add in case when item doesn't exist and there is no conflict
            if (card == null)
            {
                card       = createNew(key, value);
                table[pos] = card;
                countIncrement();
                return(card);
            }

            // loop over conflicts assigned as reference in extent field
            for (; ;)
            {
                /// key check
                if (card.Equals(key))
                {
                    /// when card was removed decrese counter
                    if (card.Removed)
                    {
                        card.Removed = false;
                        removedDecrement();
                    }
                    /// update card have same key with new value
                    card.Value = value;
                    return(card);
                }
                /// check that all conflicts was examinated and local card is the last one
                if (card.Extent == null)
                {
                    var newcard = createNew(key, value);
                    card.Extent = newcard;
                    conflictIncrement();
                    return(newcard);
                }
                card = card.Extent;
            }
        }
        public void swap_internal_cards_does_not_affect_top_or_bottom_cards()
        {
            Deck d = new Deck();

            for (int pos1 = 1; pos1 < d.Size() - 1; pos1++)
            {
                for (int pos2 = 1; pos2 < d.Size() - 1; pos2++)
                {
                    if (pos1 != pos2)
                    {
                        ICard untouchedFirst = d.PeekTopCard().Clone();
                        ICard untouchedLast  = d.PeekLastCard().Clone();
                        d.SwapCards(pos1, pos2);
                        ICard swapped1 = d.PeekCard(pos1).Clone();
                        ICard swapped2 = d.PeekCard(pos2).Clone();
                        Assert.IsTrue(untouchedFirst.Equals(d.PeekTopCard()));
                        Assert.IsTrue(untouchedLast.Equals(d.PeekLastCard()));
                    }
                }
            }
        }
        public void swap_switches_cards()
        {
            Deck d = new Deck();

            for (int pos1 = 0; pos1 < d.Size(); pos1++)
            {
                for (int pos2 = 0; pos2 < d.Size(); pos2++)
                {
                    if (pos1 != pos2)
                    {
                        ICard unswapped1 = d.PeekCard(pos1).Clone();
                        ICard unswapped2 = d.PeekCard(pos2).Clone();
                        d.SwapCards(pos1, pos2);
                        ICard swapped1 = d.PeekCard(pos1).Clone();
                        ICard swapped2 = d.PeekCard(pos2).Clone();
                        Assert.IsTrue(unswapped1.Equals(swapped2));
                        Assert.IsTrue(unswapped2.Equals(swapped1));
                    }
                }
            }
        }
        public void verify_initial_hands_dealt_alternately()
        {
            Dealer  dealer = new Dealer();
            IPlayer player = new HumanPlayer();
            Deck    deck   = new BlackJack.Deck();

            ICard card0 = deck.PeekCard(0);
            ICard card1 = deck.PeekCard(1);
            ICard card2 = deck.PeekCard(2);
            ICard card3 = deck.PeekCard(3);

            ops.DealInitialHands(deck, dealer, player);
            ICard playerCard0 = player.GetHand().GetCards()[0];
            ICard playerCard1 = player.GetHand().GetCards()[1];
            ICard dealerCard0 = dealer.GetHand().GetCards()[0];
            ICard dealerCard1 = dealer.GetHand().GetCards()[1];

            Assert.IsTrue(card0.Equals(playerCard0));
            Assert.IsTrue(card1.Equals(dealerCard0));
            Assert.IsTrue(card2.Equals(playerCard1));
            Assert.IsTrue(card3.Equals(dealerCard1));
        }
Example #13
0
        public void EqualityToNullIsFalse()
        {
            ICard cardOne = texasHoldEmBuilder.CreateNewCard(CardValue.Eight, CardSuit.Diamond);

            Assert.IsFalse(cardOne.Equals(null));
        }
Example #14
0
        public async Task SelectCardAsync(ICard card)
        {
            try
            {
                if (!timer.Enabled)
                {
                    timerStart = DateTime.Now;
                    timer.Start();
                }

                // Simplify conditional expression
                if (!card.IsTurned ? !isTurningInProgress : false)
                {
                    card.IsTurned = true;

                    // Invert condition
                    if (lastCardSelected is not null)
                    {
                        // extract method `SelectSecondCard`
                        if (card.Equals(lastCardSelected))
                        {
                            // Remove redundant equality
                            if (PlayerTurn == true)
                            {
                                MatchesFoundP1++;
                            }
                            else
                            {
                                MatchesFoundP2++;
                            }

                            MatchesFound++;
                            card.IsMatched = lastCardSelected.IsMatched = true;
                        }
                        else
                        {
                            isTurningInProgress = true;
                            await Task.Delay(turnDelayDuration);

                            isTurningInProgress = false;
                            PlayerTurn          = !PlayerTurn;
                            card.IsTurned       = lastCardSelected.IsTurned = false;
                        }

                        lastCardSelected = null;
                    }
                    else
                    {
                        lastCardSelected = card;
                    }

                    if (MatchesFound == CardHelpers.AllAnimals.Length)
                    {
                        timerEnd = DateTime.Now;
                        timer.Stop();
                        LatestCompletionTime = timerEnd.Value.Subtract(timerStart.Value).TotalSeconds;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }