public void PrintPossibleSolutionsSimple(SolutionBuilder <CodeColor> .SolutionsAnalysis analysis) { var stringBuilder = new StringBuilder(); for (int i = 0; i < Rules.CodeSize; i++) { int colorPossibilities = 0; Span <bool> mayBeSelected = stackalloc bool[Rules.ColorCount]; for (int colorIndex = 0; colorIndex < Rules.ColorCount; colorIndex++) { if (analysis.GetNodeValueCount(i, (CodeColor)colorIndex) > 0) { mayBeSelected[colorIndex] = true; colorPossibilities++; } } if (colorPossibilities > 1) { stringBuilder.Append('('); } bool firstElement = true; for (int j = 0; j < mayBeSelected.Length; j++) { if (mayBeSelected[j]) { if (!firstElement) { stringBuilder.Append(','); } stringBuilder.Append(Enum.GetName(typeof(CodeColor), j) !.Substring(0, 1)); } } if (colorPossibilities > 1) { stringBuilder.Append(')'); } stringBuilder.Append(' '); } stringBuilder.AppendFormat(CultureInfo.CurrentCulture, " ({0} possibilities)", analysis.ViableSolutionsFound); this.Logger.WriteLine(stringBuilder.ToString()); }
private static void PrintProbabilities(SolutionBuilder <CodeColor> .SolutionsAnalysis analysis) { // Sample grid printout: // // 1 2 3 4 // Magenta 100% 80% // Purple 0% 20% // Yellow 0% 0% // Teal // White // Orange string[] colorNames = Enum.GetNames(typeof(CodeColor)); int maxColorLength = colorNames.Select(n => n.Length).Max(); const int positionColumnWidth = 5; // Print header row with card names Console.Write(new string(' ', maxColorLength + 1)); for (int position = 1; position <= Rules.CodeSize; position++) { Console.Write($"{position,-positionColumnWidth}"); } Console.WriteLine(); for (int i = 0; i < Rules.ColorCount; i++) { Console.Write("{0,-" + (maxColorLength + 1) + "}", colorNames[i]); for (int j = 0; j < Rules.CodeSize; j++) { int percent = (int)(analysis.GetNodeValueCount(j, (CodeColor)i) * 100 / analysis.ViableSolutionsFound); string percentWithUnits = percent.ToString(CultureInfo.CurrentCulture) + "%"; Console.Write($"{percentWithUnits,-positionColumnWidth}"); } Console.WriteLine(); } }