Beispiel #1
0
        static void Main(string[] args)
        {
            ServerCommunicator.SkipServerLaunch = false;
            bool Parallelize = true;

            // Failed to find any possible distant turning point, possibly blocked by other agents.
            // string levelPath = "MANOAsArk.lvl";

            // Failed to find the agent.
            // string levelPath = "MAOneOneTwo.lvl";

            // Index was outside the bounds of the array.
            // string levelPath = "SAGroupName.lvl";

            // sub problem depth limit reached.
            // string levelPath = "MAGroupName.lvl";

            // reee
            // string levelPath = "SARegExAZ.lvl";
            // string levelPath = "MABob.lvl";

            // Pulling to faraway turn-point not yet implemented.
            //string levelPath = "MASoulman.lvl";
            //string levelPath = "SAOneOneTwo.lvl";

            // Found no path from  entity to goal.
            // string levelPath = "SAAIMAS.lvl";
            // string levelPath = "SAPOPstars.lvl";

            // Can't move into agent
            // string levelPath = "MAgroup.lvl";
            // string levelPath = "MANulPoint.lvl";

            //Not enough free space is available
            string levelPath = "MABob.lvl";

            //string levelPath = "SAWallZ.lvl";
            //string levelPath = "SAgTHIRTEEN.lvl";
            //string levelPath = "SANulPoint.lvl";
            //string levelPath = "SATheBTeam.lvl";
            //string levelPath = "MAgTHIRTEEN.lvl";
            //string levelPath = "MAMKM.lvl";
            //string levelPath = "MASubpoena.lvl";
            //string levelPath = "MAMASAI.lvl";



            #region Mein Levels
            //string levelPath = "SAVisualKei.lvl";
            //string levelPath = "MAVisualKei.lvl";
            #endregion

            #region Optimize these
            //string levelPath = "SAanagram.lvl";
            //string levelPath = "SAtesuto.lvl";
            #endregion

            #region Bugfix
            //string levelPath = "MACorridor.lvl";
            //string levelPath = "SAsimple2.lvl";
            //string levelPath = "SADangerbot.lvl";
            #endregion

            //Not enough free space
            //string levelPath = "SAGroupOne.lvl";

            string convertedLevelPath = "temp.lvl";

            ServerCommunicator serverCom = new ServerCommunicator();
            if (args.Length == 0 && !ServerCommunicator.SkipServerLaunch)
            {
                levelPath = GetLevelPath(levelPath);
                ConvertFilesToCorrectFormat(levelPath, convertedLevelPath);

                serverCom.StartServer(convertedLevelPath);
            }
            else
            {
                ServerCommunicator.GiveGroupNameToServer();

                Level level;
                if (ServerCommunicator.SkipServerLaunch)
                {
                    levelPath = GetLevelPath(levelPath);
                    ConvertFilesToCorrectFormat(levelPath, convertedLevelPath);
                    level = Level.ReadLevel(File.ReadAllLines(convertedLevelPath));
                }
                else
                {
                    level = ServerCommunicator.GetLevelFromServer();
                }

                var highLevelCommands = ProblemSolver.SolveLevel(level, TimeSpan.FromHours(1), false);
                var lowLevelCommands  = serverCom.NonAsyncSolve(level, highLevelCommands);

                if (!Parallelize)
                {
                    serverCom.SendCommandsSequentially(lowLevelCommands, level);
                }
                else
                {
                    var finalCommands = CommandParallelizer.Parallelize(lowLevelCommands, level);
                    serverCom.SendCommands(finalCommands);
                }
                Console.Read();
                return;
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //List<string> filePaths = GetFilePathsFromFolderRecursively("Levels\\Old_Format\\comp_levels_2017"); // 68.37
            //List<string> filePaths = GetFilePathsFromFolderRecursively("Levels\\Old_Format\\real_levels"); // 81.41
            List <string> filePaths = GetFilePathsFromFolderRecursively("Levels\\New_Format\\comp_levels"); // 66.44
            ConcurrentBag <SolveStatistic> statisticsBag      = new ConcurrentBag <SolveStatistic>();
            ConcurrentBag <LevelStatistic> levelStatisticsBag = new ConcurrentBag <LevelStatistic>();

            Stopwatch watch = new Stopwatch();

            watch.Start();
            Parallel.ForEach(filePaths, x =>
            {
                var statistic  = ProblemSolver.GetSolveStatistics(x, TimeSpan.FromSeconds(20), false);
                int?movesCount = null;

                if (statistic.Status == SolverStatus.SUCCESS)
                {
                    try
                    {
                        long startTime = watch.ElapsedMilliseconds;
                        var sc         = new ServerCommunicator();
                        var commands   = sc.NonAsyncSolve(statistic.Level, statistic.Solution);
                        movesCount     = CommandParallelizer.Parallelize(commands, statistic.Level).Length;
                        long endTime   = watch.ElapsedMilliseconds;

                        levelStatisticsBag.Add(new LevelStatistic(x, statistic.LevelName, movesCount.Value, endTime - startTime));
                    }
                    catch (Exception e)
                    {
                        statistic.Status      = SolverStatus.ERROR;
                        statistic.ErrorThrown = e;
                    }
                }

                Console.WriteLine($"{statistic.Status.ToString()} {Path.GetFileName(x)} Time: {statistic.RunTimeInMiliseconds} Moves: {(movesCount ?? -1)}");
                statisticsBag.Add(statistic);
            });
            watch.Stop();
            List <SolveStatistic> statistics = statisticsBag.ToList();

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            var errorGroups = statistics.Where(x => x.Status == SolverStatus.ERROR)
                              .GroupBy(x => string.Join(Environment.NewLine, x.ErrorThrown.StackTrace.Split(Environment.NewLine).Take(2)))
                              .OrderByDescending(x => x.Count())
                              .ToList();

            foreach (var errorGroup in errorGroups)
            {
                var orderedErrors = errorGroup.OrderBy(x => x.ErrorThrown.StackTrace.Split(Environment.NewLine).Length);
                Console.WriteLine("Levels with this error:");
                Console.WriteLine(string.Join(Environment.NewLine, orderedErrors.Select(x => x.LevelName)));
                Console.WriteLine();
                Console.WriteLine("Error: ");
                var splittedError = orderedErrors.First().ErrorThrown.StackTrace.Split(Environment.NewLine);
                Console.WriteLine(orderedErrors.First().ErrorThrown.Message + Environment.NewLine + string.Join(Environment.NewLine, splittedError.Take(Math.Min(15, splittedError.Length))));
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Timeout:");
            Console.WriteLine(string.Join(Environment.NewLine, statistics.Where(x => x.Status == SolverStatus.TIMEOUT).Select(x => x.LevelName)));

            Console.WriteLine();
            Console.WriteLine($"Total time: {watch.ElapsedMilliseconds}");
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine($"Success: {statistics.Sum(x => x.Status == SolverStatus.SUCCESS ? 1 : 0)}");
            Console.WriteLine($"Timeout: {statistics.Sum(x => x.Status == SolverStatus.TIMEOUT ? 1 : 0)}");
            Console.WriteLine($"Error  : {statistics.Sum(x => x.Status == SolverStatus.ERROR ? 1 : 0)}");

            foreach (var scoreData in ScoresData)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();

                var score = scoreData.GetScore(levelStatisticsBag.ToList());
                Console.WriteLine($"Competition: {scoreData.CompetitionName}");
                Console.WriteLine($"SA move score: {score.SAMoveScore.ToString("N2")}");
                Console.WriteLine($"SA time score: {score.SATimeScore.ToString("N2")}");
                Console.WriteLine($"MA move score: {score.MAMoveScore.ToString("N2")}");
                Console.WriteLine($"MA time score: {score.MATimeScore.ToString("N2")}");
                Console.WriteLine($"Times faster:  {score.TimesFaster.ToString("N2")}");
                Console.WriteLine();
                Console.WriteLine($"Moves score:   {(score.SAMoveScore + score.MAMoveScore).ToString("N2")}");
                Console.WriteLine($"Time score:    {(score.SATimeScore + score.MATimeScore).ToString("N2")}");
                Console.WriteLine($"Total score:   {(score.SAMoveScore + score.MAMoveScore + score.SATimeScore + score.MATimeScore).ToString("N2")}");
            }


            Console.Read();
        }