/// <summary>Gets a <seealso cref="ValueCounterDictionary{TKey}"/> that contains the number of occurrences of each role in this list. This ignores the <seealso cref="RoleAlignment"/> slots.</summary> /// <returns>The <seealso cref="ValueCounterDictionary{TKey}"/> containing the number of occurrences of each role in this list.</returns> public ValueCounterDictionary <Type> GetRoleOccurrences() { var result = new ValueCounterDictionary <Type>(); FixedRoleSlots.ForEach(role => result.Add(role.GetType())); return(result); }
public void AddTest() { var d = new ValueCounterDictionary <char>(testDictionary); d.Add('a', 4); Assert.AreEqual(5, d['a']); }
public static void InitializeTestDictionary() { for (int i = 0; i < 5; i++) { testDictionary.Add((char)('a' + i)); } }
public override long SolvePart2() { var locationOffsets = new Location2D[] { (1, 1), (3, 1), (5, 1), (7, 1), (1, 2) }; var slopes = new ValueCounterDictionary <Location2D>(locationOffsets, 0); for (int i = 0; i < grid.Height; i++) { foreach (var o in locationOffsets) { var location = o * i; if (location.Y >= grid.Height) { continue; } if (grid[location] == TreeGridCellType.Tree) { slopes.Add(o); } } } long product = 1; foreach (var s in slopes) { product *= s.Value; } return(product); }
public void AdjustCountersTest() { var d = new ValueCounterDictionary <char>(testDictionary); d.Add('a', 4); d.AdjustCounters('a', 'b', 3); Assert.AreEqual(2, d['a']); Assert.AreEqual(4, d['b']); }
public PrintableGrid(PrintableGrid <T> other) : this(other.Width, other.Height) { for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { Grid[x, y] = other.Grid[x, y]; } } foreach (var v in other.ValueCounters) { ValueCounters.Add(v); } }
private bool ValidateRoleList(RoleCollection availableRoles, out ValueCounterDictionary <Type> remainingSlots) { remainingSlots = new(); // This exists to prevent impossible role lists like more than 6 Coven roles in a game (since all the Coven roles are unique) var remainingAlignmentSlots = new ValueCounterDictionary <Faction>(); foreach (var t in availableRoles) { var instance = RoleInstancePool.Instance[t]; remainingSlots.Add(t, instance.MaximumOccurrences); remainingAlignmentSlots.Add(instance.Faction, instance.MaximumOccurrences); } foreach (var slot in roleSlots) { if (slot is RoleAlignment alignment) { } else { var role = slot as Role; // This is probably the greatest usage of inline variable declarations via is alignment = role.FullAlignment; var type = role.GetType(); remainingSlots.Subtract(type); if (remainingSlots[type] < 0) { return(false); } } var faction = alignment.Faction; if (faction == Faction.Any) { continue; } remainingAlignmentSlots.Subtract(faction); if (remainingAlignmentSlots[faction] < 0) { return(false); } } return(true); }
private int SolveProblem(SumCalculationPredicate sumCalculationPredicate) { int sum = 0; var dictionary = new ValueCounterDictionary <char>(); foreach (var group in groups) { var people = group.GetLines(); foreach (var person in people) { foreach (var question in person) { dictionary.Add(question); } } sum += dictionary.Count(kvp => sumCalculationPredicate(kvp, people.Length)); dictionary.Clear(); } return(sum); }