예제 #1
0
        public void ListAvailableContracts()
        {
            List <Player>   players      = Musketeers(5);
            BettingService  bs           = new BettingService();
            List <Contract> allContracts = AllContracts();

            var availableBets = bs.AvailableBets();

            CollectionAssert.AreEquivalent(availableBets.Select(x => x.ToString()), allContracts.Select(x => x.ToString()));

            bs.GatherBets(players);
            availableBets = bs.AvailableBets();
            var winningBet           = bs.GetWinningBet();
            var onlyGreatersPlusPass = allContracts.Where(x => x > winningBet.Value).Select(x => x.ToString()).ToList();

            if (winningBet.Value.ToString() != "pass")
            {
                onlyGreatersPlusPass.Add(new Contract("pass").ToString());
            }

            //fails (different HashCode)
            //CollectionAssert.AreEquivalent(onlyGreatersPlusPass,availableBets);

            CollectionAssert.AreEquivalent(onlyGreatersPlusPass, availableBets.Select(x => x.ToString()));
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            BettingService bettingService = new BettingService();

            var param = new {
                UserToken       = "",
                BalancePassword = "",
                GameCode        = "",
                GameType        = "",
                PlayType        = "",
                Security        = "",
                TotalMoney      = "",
                StopAfterBonus  = "",
                SavaOrder       = "",
                RedBagMoney     = "",
                IssuseList      = "",
            };
            String paramStr = JsonHelper.Serialize(param);

            bettingService.Betting(paramStr, SchemeSource.Android, "001");

            Console.ReadKey(true);
            //KaSon.FrameWork.AnalyzerFactory
        }
예제 #3
0
        public void PlayerWithWinningContractIsAttacker()
        {
            List <Player>  players = Musketeers(5);
            DealingService ds      = new DealingService(true, players);
            BettingService bs      = new BettingService();

            bs.GatherBets(players);
            var bet = bs.GetWinningBet();

            bs.AuctionIsWon(ds);

            Assert.True(bet.Key.Attacker);
        }
예제 #4
0
        public void RegisteredBetsMatchForAllPlayers(int nbPlayers)
        {
            List <Player>  players = Musketeers(nbPlayers);
            BettingService bs      = new BettingService();

            bs.GatherBets(players);

            Assert.That(bs.RegisteredBets().Count == nbPlayers);

            var registeredBets = bs.RegisteredBets();

            foreach (Player player in players)
            {
                Assert.That(registeredBets[player].ToString() == player.Contract.ToString());
            }
        }
예제 #5
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));
        }