コード例 #1
0
        private int ScoreHand(IHand hand, bool includeHiddenCards)
        {
            int totalScore   = 0;
            var cardsToScore = hand.GetCards(!includeHiddenCards);

            foreach (ICard card in cardsToScore)
            {
                totalScore += BlackjackGame.GetCardValue(card);
            }

            if (hand.AceCount() > 0)
            {
                // assume they will want to Stand on 18+
                if (totalScore > 7 && totalScore < 12)
                {
                    if (includeHiddenCards == true)   // when cards are hidden, just take lowest total
                    {
                        totalScore += 10;
                    }
                }
            }
            return(totalScore);
        }
コード例 #2
0
        public Interfaces.PlayerAction NextAction(IHand otherHand)
        {
            // we can ignore the value of the other player's hand for the dealer
            int thisTotal = _hand.Score(true);

            if (thisTotal == 21)
            {
                return(PlayerAction.Stand);
            }
            if (thisTotal > 21)
            {
                return(PlayerAction.Busted);
            }
            if (thisTotal > 17)
            {
                return(PlayerAction.Stand);
            }
            else
            {
                if (thisTotal == 17)
                {   // hit on a soft 17
                    if (_hand.AceCount() > 0)
                    {
                        return(PlayerAction.Hit);
                    }
                    // stand on a hard 17
                    else
                    {
                        return(PlayerAction.Stand);
                    }
                }
                else // less than 17
                {
                    return(PlayerAction.Hit);
                }
            }
        }