Пример #1
0
        public override void BuildCardsDeck()
        {
            Console.WriteLine("Chose number of cards:");
            var numberOfCards = int.Parse(Console.ReadLine());

            _deck = new DeckCreator(numberOfCards).Deck;
        }
Пример #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);
        }
        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;
                }
            }
        }
Пример #4
0
        public bool CreateGame(string name, string connectionId)
        {
            var user = _users.FirstOrDefault(u => u.ConnectionId == connectionId);

            while (_currentGames.Any(g => g.Name == name))
            {
                Random rnd = new Random();
                name += rnd.Next(1, 100);
            }

            var player = new Player(user);

            var game = new Game {
                Name    = name,
                Players = new List <Player> {
                    player
                },
                GameStarted = false,
                Deck        = DeckCreator.CreateCards(),
                Creator     = player
            };

            _currentGames.Add(game);

            return(true);
        }
Пример #5
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);
        }
Пример #6
0
 // ----------------------------------------- Methods ----------------------------------------- //
 // --- Awake --- //
 void Awake()
 {
     // Make singleton
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
Пример #7
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));
        }
        public void New_Deck_Should_Contain_40Cards()
        {
            //Arrange
            var deckCreator = new DeckCreator();

            //Act
            var cards = deckCreator.CreateCards();

            //Assert
            var       actualNumberOfCards   = cards.Count;
            const int expectedNumberOfCards = 40;

            Assert.AreEqual(expectedNumberOfCards, actualNumberOfCards);
        }
Пример #9
0
        public void Test_FillCards()
        {
            DeckCreator deckCreator = new DeckCreator();

            deckCreator.FillCards();
            var exCard = new Card
            {
                Value = 1,
                Suit  = Suit.Clubs
            };

            Assert.AreEqual(40, deckCreator.Cards.Count);
            Assert.AreNotEqual(exCard.DisplayName, deckCreator.Cards[0].DisplayName);
        }
Пример #10
0
        public void DiscardPileShuffledIntoDrawPile()
        {
            //Arrange
            var deckCreator = new DeckCreator();
            var player      = new Player("Player 1")
            {
                Draw    = new Queue <Card>(),
                Discard = deckCreator.CreateCards()
            };

            //Act
            var discardCardPile = deckCreator.RefillPlayerDeck(player);

            //Assert
            Assert.IsTrue(discardCardPile.Draw.Count > 0);
        }
Пример #11
0
        public void PlayEquelsCardsTest()
        {
            DeckCreator deckCreator = new DeckCreator
            {
                Cards = new List <Card>
                {
                    new Card
                    {
                        Value = 1,
                        Suit  = Suit.Clubs
                    },
                    new Card
                    {
                        Value = 1,
                        Suit  = Suit.Diamonds
                    },
                    new Card
                    {
                        Value = 10,
                        Suit  = Suit.Clubs
                    },
                    new Card
                    {
                        Value = 2,
                        Suit  = Suit.Diamonds
                    }
                }
            };
            Game game = new Game(2, 2)
            {
                DeckCreator = deckCreator
            };

            game.Deal();

            Assert.AreEqual(2, game.Players.Count);
            Assert.AreEqual(2, game.Players[0].Cards.Count);
            Assert.AreEqual(game.Players[0].Cards[0].Value, game.Players[1].Cards[0].Value);

            while (!game.IsEndOfGame())
            {
                game.Play();
                Assert.AreEqual(4, game.Players[0].CardCount);
                Assert.AreEqual(0, game.Players[1].CardCount);
            }
        }
Пример #12
0
        public void GenerateDeckTest()
        {
            var deck = DeckCreator.GenerateDeck();

            var redCards    = deck.Count(c => c.DisplayName.ToLower().Contains("red"));
            var greenCards  = deck.Count(c => c.DisplayName.ToLower().Contains("green"));
            var blueCards   = deck.Count(c => c.DisplayName.ToLower().Contains("blue"));
            var purpleCards = deck.Count(c => c.DisplayName.ToLower().Contains("purple"));
            var yellowCards = deck.Count(c => c.DisplayName.ToLower().Contains("yellow"));
            var rollCards   = deck.Count(c => c.DisplayName.ToLower().Contains("roll"));

            Assert.AreEqual(18, redCards);
            Assert.AreEqual(18, greenCards);
            Assert.AreEqual(18, blueCards);
            Assert.AreEqual(18, purpleCards);
            Assert.AreEqual(18, yellowCards);
            Assert.AreEqual(18, rollCards);
        }
Пример #13
0
        static void Main(string[] args)
        {
            PokerGame.Simulator.SimGames.SimTwoCardsInit();
            //PokerGame.Simulator.SimGamesFini.SimFiveCardsFini();
            //PokerGame.Simulator.SimGamesDistribution.SimDistribution();

            Console.WriteLine("Hello World");
            Deck          deck    = DeckCreator.CreateCards();
            List <Player> players = new List <Player>();

            players.Add(new Player("P1"));
            players.Add(new Player("P2"));
            players.Add(new Player("P3"));
            players.Add(new Player("P4"));
            Game game = new Game(deck, players);

            Result result = game.Play();

            //System.Diagnostics.Debug.WriteLine("Winer: {0} Hand: {1}", result.Winner.Name, result.Winner.Display);
            Console.WriteLine("Winer: {0} Hand: {1}", result.Winner.Name, result.Winner.Display);
        }
Пример #14
0
 private void InitializeDeck()
 {
     deck.Create(DeckCreator.Generate());
     deck.Shuffle();
 }
Пример #15
0
        public void NextRound()
        {
            RoundFinished = false;
            Round++;
            StartPlayer++;
            if (StartPlayer >= Players.Count)
            {
                StartPlayer = 0;
            }
            Deck = DeckCreator.CreateCards();

            // if the player is the only one who dropped his cards, he gets -50 points
            var playerWhoWonRound            = Players.FirstOrDefault(p => p.Deck.Count == 0);
            var anotherPlayerHasDroppedCards = Players.Where(player => player.User.ConnectionId != playerWhoWonRound.User.ConnectionId).Any(p => p.HasDroppedCards);

            if (!anotherPlayerHasDroppedCards)
            {
                playerWhoWonRound.Points -= 50;
            }

            foreach (var player in Players)
            {
                foreach (var card in player.Deck)
                {
                    player.Points += card.Value;
                }

                player.DroppedCards.Clear();

                if (Round == 2)
                {
                    player.DroppedCards = new List <List <Card> >
                    {
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        }
                    };
                    player.Deck = Deck.GetAndRemove(0, 10);
                }
                if (Round == 3)
                {
                    player.DroppedCards = new List <List <Card> >
                    {
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        }
                    };
                    player.Deck = Deck.GetAndRemove(0, 10);
                }
                if (Round == 4)
                {
                    player.DroppedCards = new List <List <Card> >
                    {
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        }
                    };
                    player.Deck = Deck.GetAndRemove(0, 10);
                }
                if (Round == 5)
                {
                    player.DroppedCards = new List <List <Card> >
                    {
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        }
                    };
                    player.Deck = Deck.GetAndRemove(0, 10);
                }
                if (Round == 6)
                {
                    player.DroppedCards = new List <List <Card> >
                    {
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        }
                    };
                    player.Deck = Deck.GetAndRemove(0, 11);
                }
                if (Round == 7)
                {
                    player.DroppedCards = new List <List <Card> >
                    {
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        }
                    };
                    player.Deck = Deck.GetAndRemove(0, 12);
                }
                if (Round == 8)
                {
                    player.DroppedCards = new List <List <Card> >
                    {
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        },
                        new List <Card>
                        {
                            new Card("empty")
                        }
                    };
                    player.Deck = Deck.GetAndRemove(0, 13);
                }

                for (int i = 0; i < player.Deck.Count; i++)
                {
                    player.Deck[i].Index = i;
                }

                player.Turn = false;
                player.CurrentAllowedMove    = MoveType.DrawCard;
                player.PlayerAskedToKeepCard = false;
                player.FeedbackOnKeepingCard = null;
                player.PlayerKnocked         = false;
                player.FeedbackOnKnock       = null;
                player.HasDroppedCards       = false;
            }

            Players[StartPlayer].Turn = true;
            DiscardPile = new List <Card>
            {
                new Card("empty")
            };
            AskToKeepCardPile = new List <Card>
            {
                new Card("empty")
            };
            DiscardPile.AddRange(Deck.GetAndRemove(0, 1));
        }
Пример #16
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);
        }
Пример #17
0
 public DeckCreatorInternal(DeckCreator deckCreator = null)
 {
     this.deckCreator = deckCreator;
 }