Beispiel #1
0
        /// <summary>
        /// Application entry point.
        /// </summary>
        /// <param name="args">Application arguments.</param>
        public static void Main(string[] args)
        {
            var size = Properties.Settings.Default.GridSize;
            var initialBlackSquares = GetInitialBlackSquares();
            var rowClues = GetClues(Properties.Settings.Default.Rows);
            var colClues = GetClues(Properties.Settings.Default.Columns);

            var solver = new GridSolver();

            solver.Initialize(size, initialBlackSquares, rowClues, colClues);

            solver.PrintGrid();

            Console.WriteLine("Performing initial analysis");

            foreach (var analysis in solver.InitialAnalysis())
            {
                Console.WriteLine(analysis);
            }

            solver.PrintGrid();

            var foundCells = 0;
            var lastFoundCells = 0;

            do
            {
                lastFoundCells = foundCells;
                foundCells = ReduceAndResolve(solver);
            } while (foundCells != lastFoundCells);

            var permutations = solver.EvaluateRemainingPermutations();

            Console.WriteLine($"Permutations remaining: {permutations}");

            var reductionSolved = solver.ReducePermutations();
            var validateSolved = solver.ValidatePermutations();
            var foundCommonCells = solver.EvaluateCommonCells();

            Console.WriteLine($"Sequences solved by reduction: {reductionSolved}");
            Console.WriteLine($"Sequences solved by validation: {validateSolved}");
            Console.WriteLine($"Common cells found: {foundCommonCells}");

            solver.PrintGrid();

            Console.ReadLine();
        }
Beispiel #2
0
        /// <summary>
        /// Runs the reduction steps and returns how many common cells were found.
        /// </summary>
        /// <param name="solver">The solver to act on.</param>
        /// <returns>The number of common cells found.</returns>
        private static int ReduceAndResolve(GridSolver solver)
        {
            var foundCommonCells = solver.EvaluateCommonCells();

            Console.WriteLine($"Common cells found: {foundCommonCells}");

            solver.PrintGrid();

            var reductionSolved = solver.ReducePermutations();

            Console.WriteLine($"Rows solved by reduction: {reductionSolved}");

            var estimate = solver.BestGuessPermutations();

            Console.WriteLine($"Estimated permutations remaining: {estimate.Item1}");
            Console.WriteLine($"Rows and columns that are still guesses: {estimate.Item2}");

            solver.PrintGrid();

            return foundCommonCells;
        }