Example #1
0
        private static void RunOnInput(string data, int numberOfAttempts, string outputPath, bool printResults = true)
        {
            IEnumerable <PizzaSlice> bestResults = null;
            var parser = new Parser();
            var pizza  = parser.ParseData(data);

            var bestScore = -2;

            for (int i = 0; i < numberOfAttempts; i++)
            {
                var solver  = new PizzaSolverBlat(pizza);
                var results = solver.Solve();

                var calc = new ScoreCalc(results);
                if (calc.Score > bestScore)
                {
                    bestResults = results;
                    bestScore   = calc.Score;
                }
            }

            var printer = new PizzaPrinter();

            printer.PrintToFile(bestResults, outputPath);
            if (printResults)
            {
                printer.PrintToConsole(pizza, bestResults);
            }
        }
Example #2
0
        public IEnumerable <PizzaSlice> Solve()
        {
            IEnumerable <PizzaSlice> slices = Solve(0, 0, Pizza.XLength - 1, Pizza.YLength - 1);

            Random rand = new Random();
            IEnumerable <PizzaSlice> maxSlices = this.EnlargeSlices(slices.ToList(), rand);
            int maxScore = ScoreCalc.GetScoreFromSlices(maxSlices);

            for (int index = 0; index < 100; index++)
            {
                IEnumerable <PizzaSlice> newSlice = this.EnlargeSlices(slices.ToList(), rand);

                int score = ScoreCalc.GetScoreFromSlices(newSlice);
                if (score > maxScore)
                {
                    maxScore  = score;
                    maxSlices = newSlice;
                }
            }

            return(maxSlices);
        }
Example #3
0
        private static int ReplaceIfBetter(string finalPath, string newPath)
        {
            if (!File.Exists(newPath))
            {
                return(0);
            }

            if (!File.Exists(finalPath))
            {
                var calc = new ScoreCalc(newPath);
                File.Move(newPath, finalPath);
                return(calc.Score);
            }

            var finalCalc = new ScoreCalc(finalPath);
            var newCalc   = new ScoreCalc(newPath);

            if (newCalc.Score > finalCalc.Score)
            {
                File.Delete(finalPath);
                File.Move(newPath, finalPath);
            }
            return(newCalc.Score - finalCalc.Score);
        }