Esempio n. 1
0
 public void TestPerformanceOnConcreteMap()
 {
     var map = new Map(Path.Combine(MapsDir, "random20_fl_50.map.txt"));
     var robotMove = RobotMove.Wait;
     var bot = new GreedyBot();
     var botWrapper = new BotWithBestMomentsMemory(bot);
     while (robotMove != RobotMove.Abort && map.State == CheckResult.Nothing)
     {
         robotMove = botWrapper.NextMove(map);
         map = map.Move(robotMove);
         botWrapper.UpdateBestSolution(map);
     }
 }
 private Tuple<RobotMove[], long> GetMoves(Map map, Tuple<Vector, SpecialTargetType> special)
 {
     var moves = new List<RobotMove>();
     var bot = new BotWithBestMomentsMemory(new GreedyBot());
     RobotMove robotMove;
     Map localMap = map;
     do
     {
         if(StopNow) return null;
         robotMove = special != null ? bot.NextMove(localMap, special.Item1, special.Item2) : bot.NextMove(localMap);
         localMap = localMap.Move(robotMove);
         bot.UpdateBestSolution(localMap);
         moves.Add(robotMove);
     } while(robotMove != RobotMove.Abort && localMap.State == CheckResult.Nothing);
     return Tuple.Create(bot.GetBestMovesAsArray(), localMap.State != CheckResult.Fail ? localMap.GetScore() : long.MinValue);
 }
Esempio n. 3
0
        private void TestBrains(Func<RobotAI> botFactory, string dir)
        {
            var now = DateTime.Now;
            var typeBot = botFactory();
            string botName = typeBot.GetType().Name;
            using (var writer = new StreamWriter(Path.Combine(TestsDir, botName + "_" + now.ToString("yyyy-MM-dd_HH-mm-ss") + ".txt")))
            {
                long sum = 0;
                WriteLineAndShow(writer, botName + " " + now.ToString("yyyy-MM-dd HH:mm:ss"));
                WriteLineAndShow(writer);
                WriteLineAndShow(writer, "\t  score: [W|N|A] <SCORE> (W - win, N - nothing, A - Abort)");
                WriteLineAndShow(writer);

                WriteLineAndShow(writer,
                    "map".PadRight(FilenamePadding)
                    + "ms".PadRight(ValuePadding)
                    + "ch?".PadRight(ValuePadding)
                    + "curScore".PadRight(ValuePadding)
                    + "prevScores    ...   moves");
                foreach (var file in Directory.GetFiles(dir, "*.map.txt"))
                {
                    string mapName = Path.GetFileNameWithoutExtension(file) ?? "NA";
                    var lines = File.ReadAllLines(file);
                    var bot = botFactory();
                    var map = new Map(lines);

                    var robotMove = RobotMove.Wait;

                    var timer = Stopwatch.StartNew();
                    var botWrapper = new BotWithBestMomentsMemory(bot);
                    while(robotMove != RobotMove.Abort && map.State == CheckResult.Nothing)
                    {
                        robotMove = (timer.Elapsed.TotalSeconds < 150) ? botWrapper.NextMove(map) : RobotMove.Abort;

                        map = map.Move(robotMove);
                        botWrapper.UpdateBestSolution(map);
                    }
                    string[] history = LoadHistory(dir, mapName, botName);
                    string result = botWrapper.BestMovesEndState.ToString()[0] + " " + botWrapper.BestScore.ToString();
                    bool resultChanged = result != history.FirstOrDefault();
                    WriteLineAndShow(writer,
                        mapName.PadRight(FilenamePadding)
                        + timer.ElapsedMilliseconds.ToString().PadRight(ValuePadding)
                        + (resultChanged ? "*" : "").PadRight(ValuePadding)
                        + result.PadRight(ValuePadding)
                        + String.Join(" ", history.Take(10)) + "  "
                        + botWrapper.GetBestMoves());
                    if (resultChanged)
                        history = new[] {result}.Concat(history).ToArray();
                    File.WriteAllLines(GetHistoryFilename(dir, mapName, botName), history);
                    sum += botWrapper.BestScore;
                }
                WriteLineAndShow(writer, sum.ToString());
            }
        }