Example #1
0
 public Map DoMove(RobotMove robotMove, Map map)
 {
     if (map.State != CheckResult.Nothing) return map;
     var resMap = map.Move(robotMove);
     AddMove(robotMove);
     UpdateMap(resMap);
     return resMap;
 }
Example #2
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);
     }
 }
Example #3
0
 private static void Main(string[] args)
 {
     string[] lines = Console.In.ReadToEnd().Split(new[] {Environment.NewLine}, StringSplitOptions.None);
     var map = new Map(lines);
     var bot = new TimeAwaredBackTrackingGreedyBot(140);
     var robotMoves = new List<RobotMove>();
     RobotMove robotMove;
     do
     {
         robotMove = bot.NextMove(map);
         robotMoves.Add(robotMove);
         map = map.Move(robotMove);
     } while(robotMove != RobotMove.Abort && map.State == CheckResult.Nothing);
     string result = robotMoves.Count > 0 ? new string(robotMoves.Select(move => move.ToChar()).ToArray()) : "A";
     Console.Write(result);
 }
Example #4
0
        private static bool CanEscapeFromUnderwater(Tuple<Vector, Stack<RobotMove>> target, Map map)
        {
            foreach (var move in target.Item2)
            {
                if (map.BeardCount > MaxBeardSize)
                    break;

                map = map.Move(move);
                if (map.State == CheckResult.Fail)
                    return false;
            }
            return
                new WaveRun(map, map.Robot)
                    .EnumerateTargets(
                        (lmap, pos, moves, stepNumber) =>
                            lmap.GetCell(pos) == MapCell.OpenedLift ||
                            !lmap.IsInWater(stepNumber, pos.Y) && lmap.GetCell(pos).CanStepUp())
                    .FirstOrDefault() != null;
        }
Example #5
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());
            }
        }
Example #6
0
        private static bool CanMoveToTargetExactlyByPath(Stack<RobotMove> robotMoves, Map map, Action<Map> analyseMap)
        {
            foreach (var move in robotMoves)
            {
                if (map.BeardCount > MaxBeardSize)
                    break;

                map = map.Move(move);
                if (map.State == CheckResult.Fail)
                    return false;
            }
            analyseMap(map);
            return true;
        }
Example #7
0
        private static bool CanMoveToTargetExactlyByPathWithNoRocksMoved(Stack<RobotMove> robotMoves, Map map)
        {
            foreach(var move in robotMoves)
            {
                if (map.BeardCount > MaxBeardSize)
                    break;

                map = map.Move(move);

                if (map.State == CheckResult.Fail)
                    return false;
                if (map.RocksFallAfterMoveTo(map.Robot))
                    return false;
            }
            return true;
        }