示例#1
0
        public static int CountCard(Card card)
        {
            // Two-Six: +1  Ten-Ace: -1
            switch (card.GetName())
            {
                case CardName.Ace: return -1;
                case CardName.Two: return 1;
                case CardName.Three: return 1;
                case CardName.Four: return 1;
                case CardName.Five: return 1;
                case CardName.Six: return 1;
                case CardName.Ten: return -1;
                case CardName.Jack: return -1;
                case CardName.Queen: return -1;
                case CardName.King: return -1;
            }

            return 0;
        }
示例#2
0
 public int AddCard(Card card)
 {
     this.cards.Push(card);
     return cards.Count;
 }
示例#3
0
        public static PlayerAction DeterminePlayerAction(CardCollection playerHand, Card dealerCard, bool canSplit)
        {
            // if the player has no cards, just hit
            if (playerHand == null || playerHand.Count() == 0)
                return PlayerAction.Hit;

            // if none of the player hand values are below 21, just stand
            if (playerHand.GetValues().Where(v => v < 21).Count() == 0 || playerHand.GetValues().Contains(21))
                return PlayerAction.Stand;

            List<int> playerValues = playerHand.GetValues();
            int playerValue = playerValues[0];
            int dealerValue = new CardCollection(null, new List<Card>() { dealerCard }).GetValues()[0];

            // if the player hand is a pair
            if (playerHand.IsPair() && canSplit)
            {
                // set the playerValue equal to the value of just one of their cards
                playerValue = new CardCollection(null, new List<Card>() { playerHand.PeekCard() }).GetValues()[0];

                // if the dealer shows an ace
                if (dealerCard.IsAce())
                {
                    if (playerValue <= 7) return PlayerAction.Hit;
                    if (playerValue == 8 || playerHand.ContainsAce()) return PlayerAction.Split;
                    return PlayerAction.Stand;
                }
                // if the dealer shows hard value (no ace)
                if (playerValue <= 3 && dealerValue <= 7) return PlayerAction.Split;
                if (playerValue <= 3 && dealerValue >= 8) return PlayerAction.Hit;
                if (playerValue == 4 && (dealerValue == 5 || dealerValue == 6)) return PlayerAction.Split;
                if (playerValue == 4 && (dealerValue <= 4 || dealerValue >= 7)) return PlayerAction.Hit;
                if (playerValue == 5 && dealerValue <= 9) return PlayerAction.DoubleOrHit;
                if (playerValue == 5 && dealerValue == 10) return PlayerAction.Hit;
                if (playerValue == 6 && dealerValue <= 6) return PlayerAction.Split;
                if (playerValue == 6 && dealerValue >= 7) return PlayerAction.Hit;
                if (playerValue == 7 && dealerValue <= 7) return PlayerAction.Split;
                if (playerValue == 7 && dealerValue >= 8) return PlayerAction.Hit;
                if (playerValue == 8) return PlayerAction.Split;
                if (playerValue == 9 && (dealerValue == 7 || dealerValue == 10)) return PlayerAction.Stand;
                if (playerValue == 9 && (dealerValue <= 6 || dealerValue == 8 || dealerValue == 9)) return PlayerAction.Split;
                if (playerValue == 10) return PlayerAction.Stand;
                if (playerHand.ContainsAce()) return PlayerAction.Split;
            }
            // if the player has only a hard valued hand
            else if (playerValues.Where(v => v < 21).Count() == 1)
            {
                // set the playerValue equal to the one and only available value below 21
                playerValue = playerValues[0];

                // if the dealer shows an ace
                if (dealerCard.IsAce())
                {
                    if ((playerValue >= 5 && playerValue <= 10) || (playerValue >= 12 && playerValue <= 16)) return PlayerAction.Hit;
                    if (playerValue == 11) return PlayerAction.DoubleOrHit;
                    if (playerValue >= 17) return PlayerAction.Stand;
                }
                // if the dealer shows hard value (no ace)
                if (playerValue <= 8) return PlayerAction.Hit;
                if (playerValue == 9 && (dealerValue == 2 || dealerValue >= 7)) return PlayerAction.Hit;
                if (playerValue == 9 && (dealerValue >= 3 && dealerValue <= 6)) return PlayerAction.DoubleOrHit;
                if (playerValue == 10 && dealerValue <= 9) return PlayerAction.DoubleOrHit;
                if (playerValue == 10 && dealerValue == 10) return PlayerAction.Hit;
                if (playerValue == 11) return PlayerAction.DoubleOrHit;
                if (playerValue == 12 && (dealerValue == 2 || dealerValue == 3 || dealerValue >= 7)) return PlayerAction.Hit;
                if (playerValue == 12 && (dealerValue >= 4 && dealerValue <= 6)) return PlayerAction.Stand;
                if (playerValue >= 13 && playerValue <= 16 && dealerValue >= 2 && dealerValue <= 6) return PlayerAction.Stand;
                if (playerValue >= 13 && playerValue <= 16 && dealerValue >= 7) return PlayerAction.Hit;
            }
            // if the player has a soft value available
            else
            {
                // set the playerValue equal to the highest available value below 21
                playerValue = playerValues[playerValues.Where(v => v < 21).Count() - 1];

                if (dealerCard.IsAce())
                {
                    if (playerValue <= 18) return PlayerAction.Hit;
                    if (playerValue >= 19) return PlayerAction.Stand;
                }

                if (playerValue == 11) return PlayerAction.DoubleOrHit;
                if ((playerValue == 13 || playerValue == 14) && (dealerValue == 5 || dealerValue == 6)) return PlayerAction.DoubleOrHit;
                if ((playerValue == 13 || playerValue == 14) && !(dealerValue == 5 || dealerValue == 6)) return PlayerAction.Hit;
                if ((playerValue == 15 || playerValue == 16) && (dealerValue >= 4 && dealerValue <= 6)) return PlayerAction.DoubleOrHit;
                if ((playerValue == 15 || playerValue == 16) && !(dealerValue >= 4 && dealerValue <= 6)) return PlayerAction.Hit;
                if (playerValue == 17 && (dealerValue == 2 || dealerValue >= 7)) return PlayerAction.Hit;
                if (playerValue == 17 && (dealerValue >= 3 && dealerValue <= 6)) return PlayerAction.DoubleOrHit;
                if (playerValue == 18 && dealerValue <= 6) return PlayerAction.DoubleOrStand;
                if (playerValue == 18 && (dealerValue == 7 || dealerValue == 8)) return PlayerAction.Stand;
                if (playerValue == 18 && dealerValue >= 9) return PlayerAction.Hit;
                if (playerValue == 19 && dealerValue == 6) return PlayerAction.DoubleOrStand;
                if (playerValue == 19 && dealerValue != 6) return PlayerAction.Stand;
                if (playerValue == 20) return PlayerAction.Stand;
            }

            return PlayerAction.Stand;
        }