コード例 #1
0
        private bool IsCurrentMaxCardInPlayingColor(Card targetCard)
        {
            CardComparer comparer    = new CardComparer(_playingManager.CurrentAnnouncement.Type);
            bool         foundBigger = false;

            foreach (Card remCard in _playingManager.RemainingCards)
            {
                if (targetCard.CardColor == remCard.CardColor)
                {
                    if (comparer.Compare(targetCard, remCard) < 0)
                    {
                        foundBigger = true;
                        break;
                    }
                }
            }

            if (!foundBigger)
            {
                foreach (Card remCard in _playingManager.CurrentHand)
                {
                    if (targetCard.CardColor == remCard.CardColor)
                    {
                        if (comparer.Compare(targetCard, remCard) < 0)
                        {
                            foundBigger = true;
                            break;
                        }
                    }
                }
            }

            return(!foundBigger);
        }
コード例 #2
0
        public void CheckComparingCardsWithTheSameColor()
        {
            string card1 = "4C";
            string card2 = "5C";

            Assert.IsTrue(cardComparer.Compare(card1, card2) < 0);
        }
コード例 #3
0
        static void MainXXX()
        {
            //TESTING ZONE
            Console.WriteLine("=== TEST ZONE ===");
            string path = Environment.CurrentDirectory + @"..\..\..\..\Resorces\waste.csv";

            Console.WriteLine(path);

            Deck Talia = new Deck(new CardDAO(path));

            Talia.Shuffle();
            IComparer <Card> comparer = new CardComparer();
            int result = comparer.Compare(Talia.CardDeck[0], Talia.CardDeck[1]);

            Console.WriteLine($"{Talia.CardDeck[0].Degradability} : {Talia.CardDeck[1].Degradability} --> {result}");
            Talia.CardDeck.Sort(comparer);
            foreach (var card in Talia.CardDeck)
            {
                Console.WriteLine($"{card.CardName}, {card.Degradability}");
            }
            Talia.CardDeck.Sort();
            foreach (var card in Talia.CardDeck)
            {
                Console.WriteLine($"{card.CardName}, {card.TotalStatSum}");
            }

            Deck allCadrds = new Deck(new CardDAO(Environment.CurrentDirectory + @"..\..\..\..\Resorces\waste.csv"));

            SerializeToXml(allCadrds.CardDeck, Environment.CurrentDirectory + @"..\..\..\..\Resorces\waste.xml");

            List <Card> deserializedCards = DeserializeFromXml(Environment.CurrentDirectory + @"..\..\..\..\Resorces\waste.xml");

            Console.WriteLine(deserializedCards[0]);
            //TESTING ZONE END
        }
コード例 #4
0
        public void WhenTwoCardsThenHigherIsBetter()
        {
            var cardComparer = new CardComparer();
            int result       = cardComparer.Compare("2C", "1C");

            Assert.AreEqual(1, result);

            result = cardComparer.Compare("TC", "1C");
            Assert.AreEqual(1, result);

            result = cardComparer.Compare("JC", "QC");
            Assert.AreEqual(-1, result);

            result = cardComparer.Compare("KC", "AH");
            Assert.AreEqual(-1, result);
        }
コード例 #5
0
        private Card GetCurrentMaxCardInColor(CardColor color)
        {
            Card         maxCard  = null;
            CardComparer comparer = new CardComparer(_playingManager.CurrentAnnouncement.Type);

            foreach (Card card in _playingManager.RemainingCards)
            {
                if (card.CardColor == color)
                {
                    if (maxCard == null)
                    {
                        maxCard = card;
                    }

                    if (comparer.Compare(maxCard, card) < 0)
                    {
                        maxCard = card;
                    }
                }
            }

            foreach (Card card in _playingManager.CurrentHand)
            {
                if (card.CardColor == color)
                {
                    if (maxCard == null)
                    {
                        maxCard = card;
                    }

                    if (comparer.Compare(maxCard, card) < 0)
                    {
                        maxCard = card;
                    }
                }
            }

            return(maxCard);
        }
コード例 #6
0
        private void OrderCardsAndCalculateLowForPlayers(List <Player> players, List <Card>[] lowCardListForEachPlayer, List <Card> lowCardListForBoard)
        {
            SortedSet <Card> bestLowHandSoFar          = new SortedSet <Card> (new CardComparer());
            BitArray         winningPlayers            = new BitArray(players.Count(), false);
            bool             doesPlayerTieOtherPlayers = false;

            for (int i = 0; i < lowCardListForEachPlayer.Count(); i++)
            {
                SortedSet <Card> lowCardsForCurrentPlayer = new SortedSet <Card>(new CardComparer());
                foreach (Card lowCard in lowCardListForEachPlayer[i])
                {
                    if (!lowCardsForCurrentPlayer.Contains(lowCard))
                    {
                        lowCardsForCurrentPlayer.Add(lowCard);
                    }
                }
                foreach (Card lowCard in lowCardListForBoard)
                {
                    if (!lowCardsForCurrentPlayer.Contains(lowCard))
                    {
                        lowCardsForCurrentPlayer.Add(lowCard);
                    }
                }
                if (lowCardsForCurrentPlayer.Count() >= 5)
                {
                    if (bestLowHandSoFar.Count() > 0)
                    {
                        Card[] otherPlayersLowCards = new Card[bestLowHandSoFar.Count];
                        bestLowHandSoFar.CopyTo(otherPlayersLowCards);
                        Card[] currentPlayersLowCards = new Card[lowCardsForCurrentPlayer.Count];
                        lowCardsForCurrentPlayer.CopyTo(currentPlayersLowCards);
                        CardComparer crdCompare          = new CardComparer();
                        bool         isCurrentPlayerBest = false;

                        //start comparing the fifth card in both the arrays, thats what we care about.
                        for (int j = 4; j >= 0; j--)
                        {
                            int compareValue = crdCompare.Compare(otherPlayersLowCards[j], currentPlayersLowCards[j]);
                            if (compareValue > 0)
                            {
                                //Current players low cards are better(lesser rank). So it becomes the best hand.
                                isCurrentPlayerBest = true;
                                break;
                            }
                            else if (compareValue < 0)
                            {
                                break;
                            }
                            //continue if 0
                            if (j == 0)
                            {
                                doesPlayerTieOtherPlayers = true;
                            }
                        }
                        if (doesPlayerTieOtherPlayers)
                        {
                            winningPlayers.Set(i, true);
                        }
                        else if (isCurrentPlayerBest)
                        {
                            winningPlayers.SetAll(false);
                            winningPlayers.Set(i, true);
                            doesPlayerTieOtherPlayers = false;
                        }
                    }
                    else
                    {
                        bestLowHandSoFar = lowCardsForCurrentPlayer;
                        winningPlayers.Set(i, true);
                        doesPlayerTieOtherPlayers = false;
                    }
                }
            }
            int k = 0;

            if (doesPlayerTieOtherPlayers)
            {
                foreach (bool winning in winningPlayers)
                {
                    if (winning)
                    {
                        players[k].NumberOfLowTieingHands++;
                    }
                    k++;
                }
            }
            else
            {
                foreach (bool winning in winningPlayers)
                {
                    if (winning)
                    {
                        players[k].NumberOfLowWinningHands++;
                    }
                    k++;
                }
            }
        }