Ejemplo n.º 1
0
        public void PlayHand()
        {
            if (_shoe.NeedsNewShoe())
            {
                _shoe = Shoe.Create(7);
            }
            var toPlay = _players.Where(x => null != x).ToArray();
            foreach (var player in toPlay)
            {
                player.TakeCard(Deal());
            }
            _dealer.TakeCard(Deal());

            foreach (var player in toPlay)
            {
                player.TakeCard(Deal());
            }
            _dealer.TakeCard(Deal());

            if (!_dealer.Hand.IsBlackjack)
            {
                foreach (var player in toPlay)
                {
                    if (player.Hand.IsBlackjack)
                    {
                        continue;
                    }
                    PlayHand(player);
                }
                PlayHand(_dealer);
            }
            Payout(toPlay, _dealer);
        }
Ejemplo n.º 2
0
        public void PlayHand(Shoe shoe, Player[] players, Player dealer)
        {
            Card dealersTopCard = SeedTable(players, dealer, shoe);

            bool outstanding = false;

            if (!dealer.Hand.IsBlackjack)
            {
                foreach (Player player in players)
                {
                    if (player.Hand.IsBlackjack)
                        continue;
                    outstanding |= PlayHand(player, dealersTopCard, shoe);
                }
                if (outstanding)
                    PlayHand(dealer, dealersTopCard, shoe);
            }
            Payout(players, dealer);
        }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            Trace.Listeners.Add(new ConsoleTraceListener());

            var table = new Table();
            Player[] players = {
                new Player("Book Guy 1", new ByTheBookStrategy()),
                new Player("Book Guy 2", new ByTheBookStrategy()),
                //new Player("Bad guy 1", new ImbicileStrategy()),
                //new Player("Mad man", new RandomStrategy()),
            };
            var dealer = new Player("Dealer", new DealerStrategy());
            var shoe = new Shoe(7);
            for (var i = 0; i < 10000; i++)
            {
                if(shoe.NeedsNewShoe())
                    shoe = new Shoe(7);
                table.PlayHand(shoe, players, dealer);
            }
            ReportStats(players, dealer);
            Console.Read();
        }
Ejemplo n.º 4
0
        Card SeedTable(Player[] players, Player dealer, Shoe shoe)
        {
            players.ForEach(x => x.TakeCard(shoe.GetNextCard()));
            dealer.TakeCard(shoe.GetNextCard());
            players.ForEach(x => x.TakeCard(shoe.GetNextCard()));

            Card dealerTopCard = shoe.GetNextCard();
            dealer.TakeCard(dealerTopCard);

            return dealerTopCard;
        }
Ejemplo n.º 5
0
 bool PlayHand(Player player, Card dealerTopCard, Shoe shoe)
 {
     PlayAction play = player.Play(player.Hand, dealerTopCard);
     if (play == PlayAction.Stay)
     {
         return true;
     }
     if (play == PlayAction.Hit)
     {
         Card card = shoe.GetNextCard();
         bool bust = player.TakeCard(card);
         if (bust)
             return false;
         return PlayHand(player, dealerTopCard, shoe);
     }
     if (play == PlayAction.Double)
     {
         if (player.Hand.Count() != 2)
             throw new Exception("only double on first");
         var bust = player.TakeCard(shoe.GetNextCard());
         if (bust)
             return false;
         return true;
     }
     throw new InvalidOperationException("shouldn't be here");
 }
Ejemplo n.º 6
0
 public BlackjackTable()
 {
     DealerHand = new DealerHand();
     Shoe = new Shoe(6);
 }
Ejemplo n.º 7
0
 public BlackjackGame(BlackjackSettings settings)
 {
     Settings = settings;
     _shoe = new Shoe(settings.DecksPerShoe);
 }