public override void Populate() { var cell = minEntropy.minCell; var total = 0f; for (int i = 0; i < relativeFrequency.frequencies.Count; i++) { if (cell.gridCell.value.possible.Any(p => p.id == i)) { total += relativeFrequency.frequencies[i]; } } var random = Random.Range(0f, 1f); var selectionValue = Range.Map(random, 0, 1, 0, total); var currentSum = 0f; for (int i = 0; i < relativeFrequency.frequencies.Count; i++) { if (cell.gridCell.value.possible.Any(p => p.id == i)) { currentSum += relativeFrequency.frequencies[i]; if (selectionValue <= currentSum) { selection = cell.gridCell.value.possible.Where(p => p.id == i).First(); break; } } } cell.gridCell.value.possible.Clear(); cell.gridCell.value.possible.Add(selection); outputGridPossibilities.RefreshCounts(); }
public override void Populate() { var queue = new Queue <OutputGridPossibilities.OutputCell>(); var visited = new List <OutputGridPossibilities.OutputCell>(); queue.Enqueue(minEntropy.minCell.gridCell); while (queue.Count > 0) { var cell = queue.Dequeue(); visited.Add(cell); var combinedRule = new GatherRules.Rule(); foreach (var possibility in cell.value.possible) { var rule = gatherRules.rules.First(r => r.pattern == possibility); foreach (var neighbor in rule.possibilities.Keys) { combinedRule[neighbor].AddRange(rule[neighbor].Except(combinedRule[neighbor])); } } foreach (var neighbor in combinedRule.possibilities.Keys) { var previousCount = cell[neighbor].value.possible.Count; var tempList = new List <PatternIds.Item>(cell[neighbor].value.possible); cell[neighbor].value.possible.RemoveAll(item => !combinedRule[neighbor].Contains(item)); var count = cell[neighbor].value.possible.Count; if (count != previousCount) { if (!visited.Contains(cell[neighbor])) { queue.Enqueue(cell[neighbor]); } } if (count == 0) { queue.Clear(); } } } foreach (var cell in visited) { outputGrid.grid.SetValue(cell.value, cell.x, cell.y); } outputGrid.RefreshCounts(); }