Ejemplo n.º 1
0
 public DrinkState(DrinkState template)
 {
     drinkContents = new Dictionary <Ingredient, int>();
     foreach (var content in template.GetContents())
     {
         drinkContents.Add(content.Key, content.Value);
     }
 }
Ejemplo n.º 2
0
        private static int GetAlcoholAmount(DrinkState drink)
        {
            var drinkContents = drink.GetContents();
            var alcholAmount  = 0;

            foreach (var ingredientAmt in drinkContents)
            {
                if (Ingredients.IsAlcoholic(ingredientAmt.Key))
                {
                    alcholAmount += ingredientAmt.Value;
                }
            }
            return(alcholAmount);
        }
Ejemplo n.º 3
0
        private static float GetDifference(DrinkState goal, DrinkState drink)
        {
            var goalContents  = goal.GetContents();
            var drinkContents = drink.GetContents();

            var totalGoalIngredients = 0;
            var totalDifference      = 0;

            foreach (var ingredientAmt in goalContents)
            {
                var ingredient = ingredientAmt.Key;
                var goalAmt    = ingredientAmt.Value;

                totalGoalIngredients += goalAmt;

                int amtDrink;
                drinkContents.TryGetValue(ingredient, out amtDrink);

                var difference = Mathf.Abs(goalAmt - amtDrink);
                if (difference != 0)
                {
                    totalDifference += difference;
                }
            }

            foreach (var ingredientAmt in drinkContents)
            {
                var ingredient = ingredientAmt.Key;
                var amt        = ingredientAmt.Value;

                if (!goalContents.ContainsKey(ingredient))
                {
                    totalDifference += amt;
                }
            }

            return(Mathf.Min(totalDifference / (float)totalGoalIngredients, 1.0f));
        }
Ejemplo n.º 4
0
 public static bool IsIdentical(DrinkState goal, DrinkState drink)
 {
     // ReSharper disable once CompareOfFloatsByEqualityOperator
     return(GetDifference(goal, drink) == 0.0f);
 }
Ejemplo n.º 5
0
 public static bool IsNonAlcoholic(DrinkState drink)
 {
     return(GetAlcoholAmount(drink) == 0);
 }