public static void SimDistribution()
        {
            Deck          deck    = DeckCreator.CreateCards();
            List <Player> players = new List <Player>();

            for (int i = 0; i < 1; ++i)
            {
                players.Add(new Player("P" + i.ToString()));
                players[i].Cards = new List <Card>();
            }

            for (int i = 0; i < s_nTimesPerSim; ++i)
            {
                InitGame(deck, players);
                deck.Cards = DeckCreator.Shuffle(deck.Cards);
                Play(deck, players[0]);

                if (i % 10000 == 0)
                {
                    System.Diagnostics.Debug.WriteLine("Progress: Player: {0} Time: {1} Hand: {2}", players[0].Display, i, players[0].Cards[0].DisplayCard);
                }

                if (HandRank.StraightFlush == players[0].Hand.HandRank)
                {
                    System.Diagnostics.Debug.WriteLine("End: Player: {0} Time: {1} Hand: {2}", players[0].Display, i, players[0].Hand.HandRank);
                    break;
                }
            }
        }
Пример #2
0
        public void ShuffleTest()
        {
            var deck         = DeckCreator.GenerateDeck();
            var shuffledDeck = DeckCreator.Shuffle(deck).ToList();

            var allSame     = true;
            var currentCard = shuffledDeck[0];

            for (int i = 1; i < 18; i++)
            {
                if (shuffledDeck[i].GetType() != currentCard.GetType())
                {
                    allSame = false;
                }
                if (shuffledDeck[i] is NumberedCard && currentCard is NumberedCard)
                {
                    var nextCard        = shuffledDeck[i] as NumberedCard;
                    var currentNumbered = currentCard as NumberedCard;

                    if (currentNumbered.Color != nextCard.Color || currentNumbered.Number != nextCard.Number)
                    {
                        allSame = false;
                    }
                }
            }

            Assert.IsFalse(allSame);
        }
Пример #3
0
        public static void SimFiveCardsFini()
        {
            Deck          deck    = DeckCreator.CreateCards();
            List <Player> players = new List <Player>();

            for (int i = 0; i < 4; ++i)
            {
                players.Add(new Player("P" + i.ToString()));
                players[i].Cards = new List <Card>();
            }

            Card[]      arAxis  = deck.Cards.ToArray();
            List <Card> lstAxis = new List <Card>(arAxis);

            lstAxis.Sort(Comparer <Card> .Create((x, y) =>
                                                 (x.Rank < y.Rank || (x.Rank == y.Rank && x.Suit < y.Suit)) ? 1 :
                                                 (x.Rank > y.Rank || (x.Rank == y.Rank && x.Suit > y.Suit)) ? -1 : 0));
            arAxis = lstAxis.ToArray();

            string[] arHandRankNames = System.Enum.GetNames(typeof(HandRank));

            double[][] arReport = new double[arHandRankNames.Length][];
            for (int i = 0; i < arHandRankNames.Length; ++i)
            {
                arReport[i] = new double[arAxis.Length];
                for (int j = 0; j < arReport[i].Length; ++j)
                {
                    arReport[i][j] = 0;
                }
            }

            for (int i = 0; i < s_nTimesPerSim; ++i)
            {
                InitGame(deck, players);
                deck.Cards = DeckCreator.Shuffle(deck.Cards);
                Game   game   = new Game(deck, players);
                Result result = game.Play();
                int    nAxis  = System.Array.IndexOf(arAxis, result.Winner.Hand.SortedCards[0]);
                ++arReport[(int)result.Winner.Hand.HandRank][nAxis];

                if (i % 1000000 == 0)
                {
                    System.Diagnostics.Debug.WriteLine("Progress: Player: {0} Time: {1}", players[0].Display, i);
                }
            }

            for (int i = 0; i < arReport.Length; ++i)
            {
                for (int j = 0; j < arReport[i].Length; ++j)
                {
                    arReport[i][j] /= s_nTimesPerSim;
                }
            }

            PrintReport(arHandRankNames, arAxis, arReport);
        }
Пример #4
0
        internal void CheckIfDeckHasEnoughCards()
        {
            // everything is fine, enough cards on the game deck
            if (Deck.Count != 0)
            {
                return;
            }

            // take cards from the discard pile and shuffle them
            var cardsFromDiscardPile = DiscardPile.GetAndRemove(1, DiscardPile.Count - 1);

            Deck.AddRange(DeckCreator.Shuffle(cardsFromDiscardPile));
        }
Пример #5
0
        public static void SimTwoCardsInit()
        {
            Deck          deck    = DeckCreator.CreateCards();
            List <Player> players = new List <Player>();

            for (int i = 0; i < 4; ++i)
            {
                players.Add(new Player("P" + i.ToString()));
                players[i].Cards = new List <Card>();
            }

            Card[]      arAxis  = deck.Cards.ToArray();
            List <Card> lstAxis = new List <Card>(arAxis);

            lstAxis.Sort(Comparer <Card> .Create((x, y) =>
                                                 (x.Rank < y.Rank || (x.Rank == y.Rank && x.Suit < y.Suit)) ? 1 :
                                                 (x.Rank > y.Rank || (x.Rank == y.Rank && x.Suit > y.Suit)) ? -1 : 0));
            arAxis = lstAxis.ToArray();

            double[][] arReport = new double[arAxis.Length][];
            for (int i = 0; i < arReport.Length; ++i)
            {
                arReport[i] = new double[arAxis.Length];
                for (int j = 0; j < arReport[i].Length; ++j)
                {
                    arReport[i][j] = 0;
                }
            }

            for (int i = 0; i < arAxis.Length - 1; ++i)
            {
                for (int j = i + 1; j < arAxis.Length; ++j)
                {
                    InitGame(deck, players);

                    Card card = deck.HaveACardUpMySleeve(arAxis[i].Rank, arAxis[i].Suit);
                    players[0].AddCard(card);
                    card = deck.HaveACardUpMySleeve(arAxis[j].Rank, arAxis[j].Suit);
                    players[0].AddCard(card);

                    deck.Save();
                    for (int k = 0; k < players.Count; ++k)
                    {
                        players[k].Save();
                    }

                    int nWin = 0;
                    for (int k = 0; k < s_nTimesPerSim; ++k)
                    {
                        deck.Load();
                        deck.Cards = DeckCreator.Shuffle(deck.Cards);
                        for (int m = 0; m < players.Count; ++m)
                        {
                            players[m].Load();
                        }

                        Game   game   = new Game(deck, players);
                        Result result = game.Play();

                        if (result.Winner == players[0])
                        {
                            ++nWin;
                        }
                    }

                    players[0].Load();
                    arReport[i][j] = (double)nWin / s_nTimesPerSim;
                    System.Diagnostics.Debug.WriteLine("Progress: Player: {0} Win: {1}", players[0].Display, (double)nWin / s_nTimesPerSim);
                }
            }

            PrintReport(arAxis, arReport);
        }