/// <summary>
        /// Prompt the user for an action
        /// </summary>
        /// <param name="hand">The user's current hand</param>
        /// <param name="dealerHoleCard">The dealer's hole card</param>
        /// <returns>The action that the user would like to perform</returns>
        public override TurnAction TakeTurn(List<Card> hand, Card dealerHoleCard)
        {
            while (true)
            {
                Console.Write("Would you like to [S]tick, [H]it, [D]ouble or S[P]lit?: ");

                switch (Console.ReadKey().KeyChar)
                {
                    case 's':
                    case 'S':
                        Console.WriteLine();
                        return TurnAction.Stick;

                    case 'h':
                    case 'H':
                        Console.WriteLine();
                        return TurnAction.Hit;

                    case 'd':
                    case 'D':
                        Console.WriteLine();
                        return TurnAction.Double;

                    case 'p':
                    case 'P':
                        Console.WriteLine();
                        return TurnAction.Split;

                    default:
                        Console.WriteLine();
                        break;

                }
            }
        }
Example #2
0
        public override TurnAction TakeTurn(List<Card> hand, Card dealerHoleCard)
        {
            bool soft;
            int value = HandHelper.GetHandValue(hand.AsReadOnly(), out soft);

            //If we're less than 17, always hit
            if (value < 17)
            {
                return TurnAction.Hit;
            }
            //If we're at 17, soft and should hit on soft 17s...
            else if (value == 17 && soft && m_hitSoftSeventeen)
            {
                return TurnAction.Hit;
            }

            return TurnAction.Stick;
        }
        /// <summary>
        /// Evaluate what this entity will do for its turn
        /// </summary>
        /// <param name="hand">The hand to evaluate</param>
        /// <param name="dealerHoleCard">The dealer's shown card</param>
        /// <returns>What action to take for this turn</returns>
        public override TurnAction TakeTurn(List<Card> hand, Card dealerHoleCard)
        {
            //Is this hand soft?
            bool soft;

            //Get the current count of this hand
            int total = HandHelper.GetHandValue(hand.AsReadOnly(), out soft);

            //Index into the action array for the dealer's hole card
            int holeCardIndex = HandHelper.GetCardValue(dealerHoleCard.Value) - 2;

            //If the hand is a pair....
            if (hand.Count == 2 && hand[0].Value == hand[1].Value)
            {
                //Check what we should do with the pair
                int pairIndexValue = HandHelper.GetCardValue(hand[0].Value) - 2;
                return s_actionMap[s_pairActions[pairIndexValue, holeCardIndex]];
            }
            //If the hand is soft and it's our first move...
            else if (soft && hand.Count == 2)
            {
                //this means we have A + ? in our hand. Find the card that is not an ace
                Card nonAce = hand.First(c => c.Value != CardName.Ace);

                //Check what we should do with this hand...
                int softIndexValue = HandHelper.GetCardValue(nonAce.Value) - 2;
                return s_actionMap[s_softActions[softIndexValue, holeCardIndex]];
            }

            //If none of the above cases match, check what action we should perform based on the hand's value
            return s_actionMap[s_hardActions[total-2, holeCardIndex]];
        }
Example #4
0
 /// <summary>
 /// Swaps two cards
 /// </summary>
 static void Swap(ref Card a, ref Card b)
 {
     Card intermediate = a;
     a = b;
     b = intermediate;
 }
Example #5
0
 /// <summary>
 /// Creates an unshuffled deck of cards
 /// </summary>
 public Deck()
 {
     int cardNumber = 0;
     for (int suit = 0; suit < 4; suit++)
     {
         for (int card = 0; card < 13; card++)
         {
             m_cards[cardNumber++] = new Card((SuitName)suit, (CardName)card);
         }
     }
 }
Example #6
0
 public abstract TurnAction TakeTurn(List<Card> hand, Card dealerHoleCard);