Exemple #1
0
        public ChipStack PayOut()
        {
            ChipStack retval = Bet;

            Bet = new ChipStack(0);
            return(retval);
        }
Exemple #2
0
 /// <summary>
 /// Creates a new hand with a set of cards.
 /// </summary>
 /// <param name="cards">Cards to add immediately to the hand</param>
 public Hand(ChipStack Ante, IEnumerable <Card> cards)
 {
     Bet         = Ante;
     _cards      = new List <Card>(cards);
     DoubledDown = false;
     ComputeValue();
 }
Exemple #3
0
 /// <summary>
 /// Creates an empty hand.
 /// </summary>
 public Hand(ChipStack Ante)
 {
     Bet         = Ante;
     _cards      = new List <Card>();
     DoubledDown = false;
     ComputeValue();
 }
Exemple #4
0
 public DarwinCCPlayer(ChipStack startingPurse)
     : base(startingPurse)
 {
     CardCount       = 0;
     CurrentBetUnits = 0;
     BetIncrement    = 0;
     Pushes          = 0;
 }
Exemple #5
0
 /// <summary>
 /// Called by the table to play insurance bets.  This calls DecideInsurance(), implemented in child classes.
 /// </summary>
 /// <returns>Returns a ChipStack with an insurance bet, otherwise null.</returns>
 public ChipStack PlayInsurance()
 {
     if (DecideInsurance())
     {
         ChipStack insurance = Chips.RemoveChips((int)(Hands[0].Bet.Value * 0.5));
         return(insurance);
     }
     return(null);
 }
Exemple #6
0
        /// <summary>
        /// Create new player object.  Every new player starts with 100,000 chips.
        /// </summary>
        public Player(ChipStack startingPurse)
        {
            Hands = new List <Hand>();
            Score = new ScorePerHand();
            Track = new PlayTrack();
            Chips = new ChipStack(0);

            if (startingPurse != null)
            {
                AcceptChips(startingPurse);
            }
        }
Exemple #7
0
 /// <summary>
 /// Used by players to double down on a hand.
 /// </summary>
 /// <param name="hand">Hand to double down</param>
 public void DoubleDown(Hand hand, ChipStack NewBet)
 {
     if (NewBet.Value != hand.Bet.Value)
     {
         throw new Exception("Error: Player tried to double down with a bet unequal to the hand bet");
     }
     if (!Rules.CheckBet(hand.Bet.Value + NewBet.Value))
     {
         throw new Exception("Error: Bet would exceed table maximum");
     }
     hand.DoubleDown(DrawCard(), NewBet);
 }
Exemple #8
0
        /// <summary>
        /// Split this hand.  Function returns a new hand with one of the cards.
        /// </summary>
        /// <returns>New hand</returns>
        public Hand Split(ChipStack Bet)
        {
            if (!this.IsSplittable)
            {
                throw new Exception("Hand cannot be split.");
            }
            Card SplitCard = this._cards[1];

            this._cards.RemoveAt(1);
            ComputeValue();
            Hand newHand = new Hand(Bet, new Card[] { SplitCard });

            newHand.ValuePrePlay  = this.ValuePrePlay;
            newHand.IsSoftPrePlay = this.IsSoftPrePlay;
            return(newHand);
        }
Exemple #9
0
        /// <summary>
        /// Used by players to split a hand.
        /// </summary>
        /// <param name="hand">Hand to be split</param>
        /// <param name="player">Player object calling this method.  Used to add the split hand to the player's list of hands.</param>
        /// <param name="NewBet">New bet to be applied to the split hand</param>
        public void Split(Hand hand, Player player, ChipStack NewBet)
        {
            if (NewBet.Value != hand.Bet.Value)
            {
                throw new Exception("Error: Player tried to double down with a bet unequal to the hand bet");
            }
            if (!Rules.CheckBet(hand.Bet.Value + NewBet.Value))
            {
                throw new Exception("Error: Bet would exceed table maximum");
            }
            Hand newHand = hand.Split(NewBet);

            Hit(hand);
            Hit(newHand);
            player.Hands.Add(newHand);
        }
Exemple #10
0
 /// <summary>
 /// Finish the round after players are done.  Compare hands, dole out winnings, collect cards, and clear Hands.
 /// </summary>
 private void Play_Finish()
 {
     // Compare player hands to the dealer.
     for (int i = 0; i < NumPlayers; i++)
     {
         foreach (Hand playerHand in Players[i].Hands)
         {
             // If dealer busted, all hands still standing win.
             if (Dealer.Hands[0].Value > 21)
             {
                 Debug.WriteLine("Player " + i.ToString() + " wins - dealer busted");
                 Players[i].Score.IncrementScore(GameResult.Won, UpCard, playerHand);
                 ChipStack Winnings = playerHand.PayOut();
                 Winnings += new ChipStack(Winnings.Value);
                 Players[i].AcceptChips(Winnings);
             }
             else
             {
                 if (playerHand.Value < Dealer.Hands[0].Value)
                 {
                     Debug.WriteLine("Player " + i.ToString() + " loses - " + playerHand.Value.ToString() + " vs " + Dealer.Hands[0].Value.ToString());
                     Players[i].Score.IncrementScore(GameResult.Lost, UpCard, playerHand);
                 }
                 if (playerHand.Value > Dealer.Hands[0].Value)
                 {
                     Debug.WriteLine("Player " + i.ToString() + " wins - " + playerHand.Value.ToString() + " vs " + Dealer.Hands[0].Value.ToString());
                     Players[i].Score.IncrementScore(GameResult.Won, UpCard, playerHand);
                     ChipStack Winnings = playerHand.PayOut();
                     Winnings += new ChipStack(Winnings.Value);
                     Players[i].AcceptChips(Winnings);
                 }
                 if (playerHand.Value == Dealer.Hands[0].Value)
                 {
                     Debug.WriteLine("Player " + i.ToString() + " pushes - " + playerHand.Value.ToString() + " vs " + Dealer.Hands[0].Value.ToString());
                     Players[i].Score.IncrementScore(GameResult.Pushed, UpCard, playerHand);
                     ChipStack Winnings = playerHand.PayOut();
                     Players[i].AcceptChips(Winnings);
                 }
             }
             DiscardCards(playerHand.ReturnCards());
         }
         Players[i].Hands.Clear();
     }
     DiscardCards(Dealer.Hands[0].ReturnCards());
     Dealer.Hands.Clear();
 }
Exemple #11
0
        /// <summary>
        /// Procedure to deal the cards.
        /// </summary>
        private void Play_Deal()
        {
            // First, obtain ante from all players, and create Hands.
            Dealer.Hands.Add(new Hand(new ChipStack(0)));
            for (int i = 0; i < NumPlayers; i++)
            {
                ChipStack ante = Players[i].RequestAnte();
                if (ante != null)
                {
                    if (!Rules.CheckBet(ante.Value))
                    {
                        Debug.WriteLine("Player tried to bet less than the table minimum, or bet more than maximum.");
                        // Refuse the ante.
                        Players[i].AcceptChips(ante);
                    }
                    else
                    {
                        Players[i].Hands.Add(new Hand(ante));
                    }
                }
            }

            // Deal em out Joliet-style.
            Dealer.Hands[0].Hit(DrawCard(true));
            for (int i = 0; i < NumPlayers; i++)
            {
                if (Players[i].Hands.Count > 0)
                {
                    Players[i].Hands[0].Hit(DrawCard());
                }
            }

            Dealer.Hands[0].Hit(DrawCard());
            for (int i = 0; i < NumPlayers; i++)
            {
                if (Players[i].Hands.Count > 0)
                {
                    Players[i].Hands[0].Hit(DrawCard());
                }
            }
        }
Exemple #12
0
 public NoBustPlayer(ChipStack startingPurse) : base(startingPurse)
 {
 }
Exemple #13
0
        /// <summary>
        /// Pass control to players to make decisions.
        /// </summary>
        /// <param name="player">Player to be handed control</param>
        private void Play_StartPlayerTurn(Player player)
        {
            // If player has a natural, mark as a win, and remove hand from play.
            if (player.Hands.Count > 0 && player.Hands[0].Value == 21)
            {
                Debug.WriteLine("table> Player has a natural");
                player.Score.IncrementScore(GameResult.Won, UpCard, player.Hands[0]);
                ChipStack Winnings = player.Hands[0].PayOut();
                Winnings += new ChipStack((int)(Winnings.Value * 1.5));
                player.AcceptChips(Winnings);
                DiscardCards(player.Hands[0].ReturnCards());
                player.Hands.RemoveAt(0);
                return;
            }

            // Hand control to the player to make decisions.
            for (int i = 0; i < player.Hands.Count; i++)
            {
                Hand CurrentHand = player.Hands[i];
                player.PlayHand(CurrentHand);
            }

            // Player is done.  Player may now have multiple hands due to splits.
            // Build a boolean table to mark busted hands to remove from the list.
            bool[] HandsToRemove = new bool[player.Hands.Count];

            // Mark busted hands in table.
            for (int i = 0; i < player.Hands.Count; i++)
            {
                Hand playerHand = player.Hands[i];
#if DEBUG
                if (playerHand.ValuePrePlay == 12 && playerHand.IsSoftPrePlay)
                {
                    Debug.WriteLine("% Found a very interesting combo");
                }
                if (playerHand.ValuePrePlay == 4 && !playerHand.IsSoftPrePlay)
                {
                    Debug.WriteLine("% Found an interesting combo");
                }
#endif
                if (playerHand.Value > 21)
                {
                    Debug.WriteLine("Player " + i.ToString() + " loses - player busted");
                    player.Score.IncrementScore(GameResult.Lost, UpCard, playerHand);
                    DiscardCards(playerHand.ReturnCards());
                    HandsToRemove[i] = true;
                }
                else
                {
                    HandsToRemove[i] = false;
                }
            }

            // Remove busted hands from the list.
            for (int i = HandsToRemove.Length - 1; i >= 0; i--)
            {
                if (HandsToRemove[i])
                {
                    player.Hands.RemoveAt(i);
                }
            }
        }
Exemple #14
0
 /// <summary>
 /// Accepts chips from the table, and adds them to the player's chip stack.
 /// </summary>
 /// <param name="stack">Stack of chips offered by the table</param>
 public void AcceptChips(ChipStack stack)
 {
     Chips += stack;
 }
Exemple #15
0
        /// <summary>
        /// Play one round of blackjack.
        /// </summary>
        public void Play()
        {
            Debug.WriteLine("table> Starting round");

            // Deal everyone in.
            Play_Deal();

#if DEBUG
            {
                Card   _upcard = this.UpCard;
                Hand[] Hands   = new Hand[NumPlayers];
                for (int i = 0; i < NumPlayers; i++)
                {
                    if (Players[i].Hands.Count > 0)
                    {
                        Hand playerHand = Players[i].Hands[0];
                        Hands[i] = playerHand;
                        if (playerHand.ValuePrePlay == 12 && playerHand.IsSoftPrePlay)
                        {
                            Debug.WriteLine("% Found a very interesting combo");
                        }
                        if (playerHand.ValuePrePlay == 4 && !playerHand.IsSoftPrePlay)
                        {
                            Debug.WriteLine("% Found an interesting combo");
                        }
                    }
                }
            }
#endif

            ChipStack[] InsuranceBets = new ChipStack[Players.Length];

            // If dealer has an ace card face up, offer insurance.
            if (UpCard.Face == Face.Ace)
            {
                for (int i = 0; i < Players.Length; i++)
                {
                    if (Players[i].Hands.Count == 1)
                    {
                        ChipStack Bet = Players[i].PlayInsurance();
                        InsuranceBets[i] = Bet;
                    }
                }
            }

            // Check for dealer natural.
            if (Dealer.Hands[0].Value == 21)
            {
                // Reveal dealer hole card.
                OnCardExposure(new CardExposedEventArgs(Dealer.Hands[0].Cards[0].Clone()));

                Debug.WriteLine("table> Dealer has a natural.  Ending play");

                // Pay out insurance bets.
                for (int i = 0; i < Players.Length; i++)
                {
                    if (InsuranceBets[i] != null)
                    {
                        ChipStack Winnings = InsuranceBets[i] + new ChipStack(InsuranceBets[i].Value);
                        InsuranceBets[i] = null;
                        Players[i].AcceptChips(Winnings);
                    }
                }
                Play_Finish();
                return;
            }

            // Dealer does not have a natural.  House pockets insurance.
            InsuranceBets.Initialize();

            // Pass control to players.
            foreach (Player player in Players)
            {
                Play_StartPlayerTurn(player);
            }

            // Reveal dealer hole card.
            OnCardExposure(new CardExposedEventArgs(Dealer.Hands[0].Cards[0].Clone()));

            // Play dealer hand.
            Dealer.PlayHand(Dealer.Hands[0]);

            // Tally score and collect player cards.
            Play_Finish();

            // If we need to reshuffle, do so now.
            if (DealerShoe.CardsLeft < ReshuffleLimit)
            {
                Reshuffle();
            }
        }
Exemple #16
0
 public DarwinPlayer(ChipStack startingPurse) : base(startingPurse)
 {
 }
Exemple #17
0
 public Dealer(ChipStack startingPurse) : base(startingPurse)
 {
 }
Exemple #18
0
 public BasicStrategyPlayer(ChipStack startingPurse) : base(startingPurse)
 {
 }
 public PositiveProgDarwinPlayer(ChipStack startingPurse)
     : base(startingPurse)
 {
 }
Exemple #20
0
 /// <summary>
 /// Add only one more card to the hand.
 /// </summary>
 /// <param name="card">Card to add</param>
 public void DoubleDown(Card card, ChipStack DDBet)
 {
     Bet += DDBet;
     Hit(card);
     DoubledDown = true;
 }
Exemple #21
0
 public void AddChips(ChipStack Stack)
 {
     Value      += Stack.Value;
     Stack.Value = 0;
 }
Exemple #22
0
 public WikiPlayer(ChipStack startingPurse) : base(startingPurse)
 {
 }