/// <summary> /// Construct Frequency Distribution for the given list of items, across all keys in itemValues /// </summary> /// <param name="li">List of items to calculate for</param> /// <param name="itemValues">Entire list of itemValues to include in the frequency distribution</param> public FrequencyDist(IReadOnlyCollection <T> li, ICollection <T> itemValues) { CalcFreqDist(li); // add items to frequency distribution that are in itemValues but missing from the frequency distribution foreach (var v in itemValues) { if (!ItemFreq.Keys.Contains(v)) { ItemFreq.Add(v, new Item { Value = v, Count = 0 }); } } // check that all values in li are in the itemValues list foreach (var v in li) { if (!itemValues.Contains(v)) { throw new Exception(string.Format("FrequencyDist: Value in list for frequency distribution not in supplied list of values: '{0}'.", v)); } } }
public Item(string s) { var strings = s.Split(','); Name = strings[0]; if (strings.Length < 2) { Freq = ItemFreq.Usual; } else { switch (strings[1]) { case "Usual": Freq = ItemFreq.Usual; break; case "Legendary": Freq = ItemFreq.Rare; break; case "Rare": Freq = ItemFreq.Rare; break; //TODO: breakpoint; default: Freq = ItemFreq.Usual; break; } } if (strings.Length < 3) { Type = ItemType.Weapon; } else { switch (strings[2]) { case "Gold": Type = ItemType.Gold; break; case "Armor": Type = ItemType.Armor; break; case "Weapon": Type = ItemType.Weapon; break; case "Potion": Type = ItemType.Potion; break; case "Card": Type = ItemType.Card; break; case "Pet": Type = ItemType.Pet; break; case "Wings": Type = ItemType.Wings; break; default: Type = ItemType.Armor; break; } } }