Inheritance: IHand
        public Dealer(Point pntlocation)
        {
            // Tell the dealer where his origin point is
            location = pntlocation;

            // Create a hand for the dealer and locate its origin at the dealer's origin
            dealerHand = new Hand(new Point(0, 0));
        }
Esempio n. 2
0
        /// <summary>
        /// 追加牌
        /// </summary>
        public void GiveAdditionalCard(Hand hand)
        {
            if (this.cards.Count < 1)
            {
                throw new InvalidOperationException();
            }

            hand.AddCard(this.cards.First());
            this.cards.RemoveAt(0);
        }
Esempio n. 3
0
 public GameState()
 {
     channel = null;
     sd = null;
     sid = 0;
     players = new Dictionary<string, bool>();
     stage = GameStage.Stopped;
     deck = new CardDeck();
     deck.Shuffle(); //Just in case
     dealerCards = new Hand();
 }
Esempio n. 4
0
        public void GiveAdditionalCard(Hand hand)
        {
            if (this.cards.Count < 1)
            {
                // TODO: Add a descriptive error message
                throw new InvalidOperationException();
            }

            hand.AddCard(this.cards.First());
            this.cards.RemoveAt(0);
        }
Esempio n. 5
0
 public PlayAction Play(Hand hand, Card dealersTopCard)
 {
     var returnValue = (PlayAction)_random.Next(6);
     if (returnValue == PlayAction.DoubleOrHit)
     {
         returnValue = hand.CanDouble ? PlayAction.Double : PlayAction.Hit;
     }
     else if (returnValue == PlayAction.DoubleOrStay)
     {
         returnValue = hand.CanDouble ? PlayAction.Double : PlayAction.Stay;
     }
     if (returnValue == PlayAction.Double && !hand.CanDouble)
     {
         returnValue = PlayAction.Hit;
     }
     return returnValue;
 }
        public Player(Point pntlocation, double dblBank, NumericUpDown betControl, playerType type, Strategy strategy, CountMethod method)
        {
            // Since the game is limited to one split (two hands), just set them up now
            hands = new Hand[2];
            hands[0] = new Hand(new Point(0, 0));
            hands[1] = new Hand(new Point(50, 0));

            // Player specific variables
            location = pntlocation;
            bank = dblBank;
            plyrStrategy = strategy;
            plyrMethod = method;
            plyrType = type;
            plyrBet = betControl;

            // Start out with one hand, they may split pairs to get two
            numberOfHands = 1;
        }
Esempio n. 7
0
        /// <summary>
        /// 初始发2张牌
        /// </summary>
        public void Deal(Hand hand)
        {
            if (this.cards.Count < 2)
            {
                throw new InvalidOperationException();
            }

            var card = this.cards.First();
            hand.AddCard(card);
            this.cards.Remove(card);

            card = this.cards.First();

            if (hand.IsDealer)
            {
                card.Flip();
            }

            hand.AddCard(card);
            this.cards.Remove(card);
        }
Esempio n. 8
0
        public void Deal(Hand hand)
        {
            if (this.cards.Count < 2)
            {
                // TODO: Add a descriptive error message
                throw new InvalidOperationException();
            }

            var card = this.cards.First();
            hand.AddCard(card);
            this.cards.Remove(card);

            card = this.cards.First();

            if (hand.IsDealer)
            {
                card.Flip();
            }

            hand.AddCard(card);
            this.cards.Remove(card);
        }
Esempio n. 9
0
 internal static void Surrender(Hand playerHand)
 {
     playerHand.Flag = HandState.Surrender;
 }
        public void DrawHands(Graphics drawingSurface, Player.LabelType labelType, Hand dealerHand, bool currentPlayer)
        {
            // This routine is responsible for drawing the player's cards and the appropriate label
            foreach( Hand hand in hands )
            {
            // Increment the drawing position
            int x = location.X + hand.HandLocation.X;
            int y = location.Y + hand.HandLocation.Y;

            // Make sure there are cards in the hand to draw.
            if( hand.Count > 0 )
            {
                // Draw the appropriate label type in the upper left corner
                switch( labelType )
                {
                    case LabelType.none:
                        break;
                    case LabelType.bothHands:
                        drawingSurface.DrawString( hand.Label(numberOfHands==1), new Font("Arial",8,FontStyle.Bold), new SolidBrush(Color.Yellow), x-10, y-20 );
                        break;
                    case LabelType.drawToHand:
                        if( hand == CurrentHand || !currentPlayer )
                            drawingSurface.DrawString( hand.Label(numberOfHands==1), new Font("Arial",8,FontStyle.Bold), new SolidBrush(Color.Yellow), x-10, y-20 );
                        break;
                    case LabelType.outcome:
                       switch( hand.Outcome( dealerHand, numberOfHands ))
                       {
                           case Hand.OutcomeType.Won:
                           case Hand.OutcomeType.Blackjack:
                               drawingSurface.DrawString("WON", new Font("Arial",8,FontStyle.Bold), new SolidBrush(Color.LimeGreen), x-10, y-20 );
                               break;
                           case Hand.OutcomeType.Lost:
                               drawingSurface.DrawString("LOST", new Font("Arial",8,FontStyle.Bold), new SolidBrush(Color.Crimson), x-10, y-20 );
                               break;
                           case Hand.OutcomeType.Push:
                               drawingSurface.DrawString("PUSH", new Font("Arial",8,FontStyle.Bold), new SolidBrush(Color.Yellow), x-10, y-20 );
                               break;
                       }
                       break;
                }

                // Increment the drawing position
                x += (int)Card.cardSpacing.Width;
                y += (int)Card.cardSpacing.Height;

                // Draw the cards.
                int cardNumber = 0;
                foreach( Card card in hand )
                {
                    if( card != null )
                    {
                        cardNumber++;
                        card.Draw( drawingSurface, new Point(x, y), true, currentPlayer && hand!=CurrentHand, hand.Doubled && cardNumber==3 );
                        x += (int)Card.cardSpacing.Width;
                        y += (int)Card.cardSpacing.Height;
                    }
                }
            }

                // Draw the bet
                drawingSurface.DrawString( "$" + TotalWager().ToString(CultureInfo.InvariantCulture), new Font("Arial",8,FontStyle.Bold), new SolidBrush(Color.DarkKhaki), location.X+110, location.Y-20 );

                // Draw the bank
                drawingSurface.DrawString( "$" + bank.ToString(CultureInfo.InvariantCulture), new Font("Arial",8,FontStyle.Bold), new SolidBrush(Color.DarkKhaki), location.X+130, location.Y );

                // Draw the running card count
                if( plyrMethod != null )
                    {
                        //drawingSurface.DrawString( plyrMethod.MethodName, new Font("Arial",6,FontStyle.Bold), new SolidBrush(Color.DarkKhaki), location.X+140, location.Y+20 );
                        drawingSurface.DrawString( plyrMethod.GetWager((double)plyrBet.Value).ToString("F0"), new Font("Arial",6,FontStyle.Bold), new SolidBrush(Color.DarkKhaki), location.X+140, location.Y+20 );
                        drawingSurface.DrawString( plyrMethod.Count.ToString("F1",CultureInfo.InvariantCulture), new Font("Arial",6,FontStyle.Bold), new SolidBrush(Color.DarkKhaki), location.X+145, location.Y+40 );
                }

            }
        public bool DoubleDown(Hand hand)
        {
            // This method determines whether a double-down is possible and,
            // if so, doubling the bet.
            int handTotal = hand.Total();

            if (((handTotal >= 7 && handTotal <= 11) || hand.IsSoft) && hand.Count == 2)
            {
                // Reduce the bank
                bank -= hand.Wager;

                // Double the bet
                hand.Wager *= 2;

                // Mark the hand as doubled so the last card is drawn at an angle
                hand.Doubled = true;

                // Tell the form that we doubled.  The form then moves on to the next player.
                return true;
            }
            return false;
        }
Esempio n. 12
0
 internal static void Hit(Hand playerHand, Dealer dealer, GameDeck gameDeck)
 {
     dealer.DrawCardToHand(gameDeck, playerHand);
 }
Esempio n. 13
0
 public PlayAction Play(Hand hand, Card dealersTopCard)
 {
     var dealerCardValue = dealersTopCard.Value;
     var softValue = hand.SoftValue;
     // TODO: complete split functionality
     //if (this.Hand.CanSplit)
     //{
     //    return _splitTable[,dealerCardValue - 1];
     //}
     PlayAction returnValue;
     if (null != softValue)
     {
         softValue -= 12;
         softValue = Math.Min(softValue.Value, 6);
         returnValue = _softTable[softValue.Value, dealerCardValue - 1];
     }
     else
     {
         var index = hand.HardValue - 8;
         index = Math.Max(index, 0);
         index = Math.Min(index, 9);
         returnValue = _hardTable[index, dealerCardValue - 1];
     }
     if (returnValue == PlayAction.DoubleOrHit)
     {
         if (hand.CanDouble)
         {
             returnValue = PlayAction.Double;
         }
         else
         {
             returnValue = PlayAction.Hit;
         }
     }
     else if (returnValue == PlayAction.DoubleOrStay)
     {
         if (hand.CanDouble)
         {
             returnValue = PlayAction.Double;
         }
         else
         {
             returnValue = PlayAction.Stay;
         }
     }
     return returnValue;
 }
Esempio n. 14
0
 public PlayAction Play(Hand hand, Card dealersTopCard)
 {
     return _strategy.Play(hand, dealersTopCard);
 }
Esempio n. 15
0
 internal static void Double(Hand playerHand, Dealer dealer, GameDeck gameDeck)
 {
     dealer.DrawCardToHand(gameDeck, playerHand);
     playerHand.Bet *= 2;
     playerHand.Flag = HandState.Stand;
 }
Esempio n. 16
0
 /// <summary>
 /// Creates a new instance of the <see cref="InsuranceRule"/> class.
 /// </summary>
 /// <param name="dealerHand">The dealer's hand.</param>
 public InsuranceRule(Hand dealerHand)
 {
     this.dealerHand = dealerHand;
 }
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="BlackjackAnimatedDealerHandComponent"/> class.
 /// </summary>
 /// <param name="place">A number indicating the hand's position on the
 /// game table.</param>
 /// <param name="hand">The dealer's hand.</param>
 /// <param name="cardGame">The associated game.</param>
 public BlackjackAnimatedDealerHandComponent(int place, Hand hand,
                                             CardsGame cardGame) : base(place, hand, cardGame)
 {
 }
Esempio n. 18
0
        public OutcomeType Outcome( Hand dealerHand, int numberOfHands )
        {
            OutcomeType returnValue = OutcomeType.None;

               bool dealerBlackjack = dealerHand.Total() == 21 && dealerHand.Count == 2;
               if( this.Total() > 0 )
               {
            if( Total() > 21 )
             returnValue = OutcomeType.Lost;
            else if( IsBlackjack() && !dealerBlackjack && numberOfHands == 1 )
             returnValue = OutcomeType.Blackjack;
            else if( dealerHand.Total() > 21 )
             returnValue = OutcomeType.Won;
            else if( Total() < dealerHand.Total() )
             returnValue = OutcomeType.Lost;
            else if( Total() > dealerHand.Total() )
             returnValue = OutcomeType.Won;
            else if( Total() == dealerHand.Total() )
             returnValue = OutcomeType.Push;
               }

               return returnValue;
        }
Esempio n. 19
0
        // ICloneable
        Object ICloneable.Clone()
        {
            Hand tmp = new Hand(cardPosition);

              for (int x = 0; x < cardPosition; x++)
              tmp.Add(cards[x]);

              return tmp;
        }
Esempio n. 20
0
        public Hand Clone()
        {
            Hand tmp = new Hand(cardPosition);

              for (int x = 0; x < cardPosition; x++)
              tmp.Add(cards[x]);

              return tmp;
        }
 public void Reset()
 {
     // Get a new hand for each round
     dealerHand = new Hand(new Point(0, 0));
 }
Esempio n. 22
0
        /// <summary>
        /// Creates a blank player.
        /// </summary>
        public Player()
        {
            nick = null;
            money = 0;
            bet = 0;

            //Stats
            blackjacks = 0;
            hands = 0;
            wins = 0;
            ties = 0;
            busts = 0;
            highestMoney = Player.StartMoney;
            splits = 0;
            dds = 0;
            surrenders = 0;
            moneyResets = 0;

            state = PlayerState.Out;
            currentCards = new Hand();
            secondHand = new Hand();
            channel = string.Empty;
        }
Esempio n. 23
0
 internal static void Stand(Hand playerHand)
 {
     playerHand.Flag = HandState.Stand;
 }
Esempio n. 24
0
 public void Reset()
 {
     Hand = new Hand();
 }
 public abstract AdviceType GetAdvice( Hand h, Card c, bool b, double cc );
Esempio n. 26
0
        public static void PlayGame()
        {
            var deck = new DeckContainer();

            if (deck.Cards.Count() < 5)
            {
                // reshuffle deck
                WriteBreak();
                Console.WriteLine("Reshuffling Deck");
                deck = new DeckContainer();
                WriteBreak();
            }

            Console.WriteLine("Let's play Blackjack");

            // Set up hands
            var dealer = new Hand("Dealer", deck.DealCard(), deck.DealCard());
            var player = new Hand("Player", deck.DealCard(), deck.DealCard());

            WriteBreak();
            Console.WriteLine("Dealers Card");
            Console.WriteLine(dealer.ShowDealerHand());

            // Player's turn
            var stoppedPlaying = false;
            while (!stoppedPlaying)
            {
                WriteBreak();
                Console.WriteLine("Your hand:");
                Console.WriteLine(player);

                WriteBreak();

                Console.WriteLine("(H)it or (S)tay");
                var action = Console.ReadLine().ToLower();
                if (action == "h")
                {
                    Console.WriteLine("hitting");
                    var newCard = deck.DealCard();
                    Console.WriteLine($"Next card {newCard}");
                    player.Cards.Add(newCard);
                    if (player.Count() >= 21)
                    {
                        Console.WriteLine("BUSTED!");
                        stoppedPlaying = true;
                    }
                }
                else if (action == "s")
                {
                    Console.WriteLine("staying");
                    stoppedPlaying = true;
                }
                else
                {
                    Console.WriteLine("Pick an action:(h)it or (s)tay ");
                }
            }

            // Dealer's Turn
            while (dealer.Count() < 16)
            {
                WriteBreak();
                Console.WriteLine("Dealer is hitting");
                Thread.Sleep(750);
                var newCard = deck.DealCard();
                Console.WriteLine($"Dealer was delt {newCard}");
                dealer.Cards.Add(newCard);
                Thread.Sleep(750);
            }

            // Game results
            // player and dealer are under 21
            // player is under, dealer is over
            // player is over, dealer is under
            // player is over, dealer is over
            // player is at 21, dealer is XXXX
            // player is XXX, dealer is at 21

            WriteBreak();

            if (player.Count() < 21 && dealer.Count() < 21)
            {
                if (player.Count() > dealer.Count())
                {
                    Console.WriteLine($"Player won with a {player.Count()} over the dealer's {dealer.Count()}");
                }
                else if (player.Count() < dealer.Count())
                {
                    Console.WriteLine($"Dealer won with a {dealer.Count()} over the player's {player.Count()}");
                }
                else
                {
                    Console.WriteLine($"Tie game! Dealer with a {dealer.Count()} and the player has {player.Count()}");
                }
            }
            else if (player.Count() < 21 && dealer.Count() > 21)
            {
                Console.WriteLine($"Player wins {player.Count()}, Dealer busts with a {dealer.Count()}");
            }
            else if (player.Count() > 21 && dealer.Count() < 21)
            {
                Console.WriteLine($"Player busts with a {player.Count()}, Dealer wins with a {dealer.Count()}");
            }
            else if (player.Count() > 21 && dealer.Count() > 21)
            {
                Console.WriteLine("Both player and dealer have busted! No winners");
            }
            else if (player.Count() == 21 && dealer.Count() != 21)
            {
                Console.WriteLine("Player hit 21. Blackjack!");
            }
            else if (player.Count() != 21 && dealer.Count() == 21)
            {
                Console.WriteLine("Dealer hit 21. Blackjack!");
            }
            else if (player.Count() == 21 && dealer.Count() == 21)
            {
                Console.WriteLine("Both hit 21! Winner, Winner");
            }
        }
 public void Blackjack(Hand hand)
 {
     // Since the bet is taken from the bank at the beginning of play,
     // give it back plus 1.5 times the wager.
     bank += hand.Wager + hand.Wager * 1.5;
 }