Пример #1
0
        /**
         * <summary>This method takes in a players hand, calculate the worth of the hand and returns it.</summary>
         * <param name="hand">List of cards representing the players hand</param>
         * <returns>An integer value representing the worth</returns>
         */
        public static int HandWorth(List <Card> hand)
        {
            var handWorthWithoutAceChange = 0;
            var aceCount = 0;

            //Work out the total worth in hand without changing ace values (ace default value is 1)
            try
            {
                foreach (var card in hand)
                {
                    var value = ValueCalculator.CardWorth(card);
                    if (value == 1)
                    {
                        aceCount++;
                        handWorthWithoutAceChange += value;
                    }
                    else
                    {
                        handWorthWithoutAceChange += value;
                    }
                }
            } catch (NullReferenceException) {}


            //If there is at least one ace, see if the worth of the ace(s) should change
            if (aceCount > 0)
            {
                handWorthWithoutAceChange = AceChange(aceCount, handWorthWithoutAceChange);
            }

            return(handWorthWithoutAceChange);
        }