Esempio n. 1
0
        private static int GetMaxScore(Stack<Ingredient> freeIngredients, Cookie cookie)
        {
            if (freeIngredients.Count==0)
            {
                return cookie.GetScore();
            }

            var ingredientToAdd = freeIngredients.Pop();
            var teaspoonsCount = cookie.TeaspoonsCount;
            var maxScore = 0;
            for (int i = 0; i <= TotalTeaspoonsCount-teaspoonsCount; i++)
            {
                cookie.AddIngredientDose(ingredientToAdd, i);
                var score = GetMaxScore(freeIngredients, cookie);
                if (score>maxScore)
                {
                    maxScore = score;
                }
                cookie.RemoveIngredient(ingredientToAdd);
            }
            freeIngredients.Push(ingredientToAdd);

            return maxScore;
        }