示例#1
0
        private static void CodeBreaker()
        {
            var builder = Rules.CreateSolutionBuilder();

            int breakerAttemptsCount = 0;

            while (true)
            {
                ReadOnlyMemory <CodeColor> guess = InputCode($"Input guess #{++breakerAttemptsCount}: ");
                Response response = InputResponse();
                builder.AddResponse(guess, response);

                SolutionBuilder <CodeColor> .SolutionsAnalysis analysis = builder.AnalyzeSolutions(CancellationToken.None);
                analysis.ApplyAnalysisBackToBuilder();
                if (analysis.ViableSolutionsFound == 1)
                {
                    Console.WriteLine("Solution found!");
                    break;
                }

                Console.WriteLine($"{analysis.ViableSolutionsFound} solutions remaining.");

                PrintProbabilities(analysis);
                PrintSuggestedGuess(builder, CancellationToken.None);
            }
        }