public DrinkState(DrinkState template) { drinkContents = new Dictionary <Ingredient, int>(); foreach (var content in template.GetContents()) { drinkContents.Add(content.Key, content.Value); } }
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); }
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)); }
public static bool IsIdentical(DrinkState goal, DrinkState drink) { // ReSharper disable once CompareOfFloatsByEqualityOperator return(GetDifference(goal, drink) == 0.0f); }
public static bool IsNonAlcoholic(DrinkState drink) { return(GetAlcoholAmount(drink) == 0); }