Exemple #1
0
    public static Tuple <Solution, int> FindSolution(Map map, Robot[] robots)
    {
        var platformCells = map.EmptyCells;

        Solution  bestSolution = null;
        int       bestScore    = -1;
        Stopwatch watch        = Stopwatch.StartNew();

        int simulationCount = 0;

        while (watch.ElapsedMilliseconds < 970)
        {
            var solution = RandomSolutionFinder.GenerateRandomSolution(map, platformCells);

            //Evaluate
            var newMap = map.Apply(solution.Arrows);
            int score  = ScoreCalculator.ComputeScore(newMap, robots);

            if (score > bestScore)
            {
                bestScore    = score;
                bestSolution = solution;
            }

            simulationCount++;
        }

        Player.Debug($"Nb Simulation {simulationCount.ToString()} in {watch.ElapsedMilliseconds.ToString()}ms");
        Player.Debug($"Best score achieved: {bestScore.ToString()}");

        return(new Tuple <Solution, int>(bestSolution, bestScore));
    }