Example #1
0
        public void AfterDealingRoundNumberIsZero()
        {
            List <Player>  players        = Musketeers(5);
            DealingService dealingService = new DealingService(true, players);
            PlayerService  playerService  = new PlayerService();
            DealingRules   rules          = new DealingRules();

            playerService.MakeDealer(players.First());
            dealingService.DealsAllCardsFromDeck();

            Assert.That(dealingService.GetRoundNumber() == 0);
        }
Example #2
0
        public void PlayOneGame(int nbPlayers)
        {
            DealingRules   dealingRules   = new DealingRules();
            BettingService bettingService = new BettingService();
            PlayerService  playerService  = new PlayerService();
            List <Player>  players        = playerService.CreatePlayers(Musketeers().Take(nbPlayers)).ToList();
            DealingService dealingService = new DealingService(false, players);
            RoundService   roundService   = new RoundService(false, players);

            Player dealer = players.First();

            dealer.Dealer = true;
            dealingService.DealsAllCardsFromDeck();

            Assert.That(dealingService.NbPlayers(), Is.EqualTo(nbPlayers));
            Assert.That(dealingService.CountAside(), Is.EqualTo(dealingRules.AsideMaxCards(nbPlayers)));
            Assert.NotNull(dealingService.GetDealer());
            Assert.Zero(dealingService.GetRoundNumber());
            Assert.That(dealingService.DealtAsideIsCorrect(), Is.True);

            foreach (Player player in players)
            {
                Assert.That(player.Hand.Count == players.First().Hand.Count);
                Assert.That(player.Contract.ToString(), Is.EqualTo("pass"));
            }

            bettingService.GatherBets(players);
            bettingService.AuctionIsWon(dealingService);
            Player attacker = bettingService.GetWinningBet().Key;

            playerService.MakeAside(attacker, dealingService.NbCardsInAside());

            // Put this in dealing service ?
            // Game is ready to start when:
            Assert.That(attacker.Hand.Count, Is.EqualTo(players.First(x => x.Attacker is false).Hand.Count));
            Assert.That(attacker.WonHands.Count, Is.EqualTo(dealingRules.AsideMaxCards(nbPlayers)));
            Assert.Zero(dealingService.GetRoundNumber());

            while (dealer.Hand.Count > 0)
            {
                var round = roundService.PlayRound();
            }

            Assert.Zero(players.Select(x => x.Hand.Count).Sum());
            Assert.That(players.Select(x => x.WonHands.Count).Sum(), Is.EqualTo(DealingRules.MaxCardsInDeck));
            Assert.That(players.Select(x => x.WonHands.Cast <Card>().Score()).Sum(), Is.EqualTo(CardCountingRules.MaxScore));
        }
Example #3
0
        public void SendAsideToWinnerMakesPlayerHaveMoreCardThanOthers(int nbPlayers)
        {
            var players = Musketeers(nbPlayers);

            players.First().Dealer = true;
            DealingService ds      = new DealingService(true, players);

            ds.DealsAllCardsFromDeck();
            Player attacker = ds.NextPlayer();

            attacker.Attacker = true;

            ds.SendAsideToPlayerHand(attacker);

            while (ds.GetRoundNumber() == 0)
            {
                Player player = ds.NextPlayer();
                Assert.That(attacker.Hand.Count, Is.GreaterThan(player.Hand.Count));
            }
        }
Example #4
0
        public void CheckNbCardsInPlayersHandsAndAsideIsCorrect(int nbPlayers)
        {
            List <Player>  players        = Musketeers(nbPlayers);
            DealingService dealingService = new DealingService(true, players);
            PlayerService  playerService  = new PlayerService();
            DealingRules   rules          = new DealingRules();

            int totalCardsInHand = 0;

            playerService.MakeDealer(players.First());
            dealingService.DealsAllCardsFromDeck();

            foreach (Player player in players)
            {
                totalCardsInHand += playerService.CountCardsInHand(player);
                Assert.AreEqual(players[0].Hand.Count(), player.Hand.Count()); //all players have same nb cards
                Assert.IsEmpty(player.WonHands);                               //no player has an aside
            }

            Assert.AreEqual(DealingRules.MaxCardsInDeck, totalCardsInHand + dealingService.CountAside()); //all cards are dealt
            Assert.AreEqual(rules.AsideMaxCards(nbPlayers), dealingService.CountAside());                 //aside has expected number of cards
        }