Example #1
0
        public RobotAction[] NextStep(RobotManager robot, RobotResult result, int limit)
        {
            if (!robot.Map.Explored(robot.Position.Move((byte)robot.Rot + 2)))
                return new[] { RobotAction.Left };

            var r = (byte)GetNextStepPoint(robot, limit);
            r -= (byte)robot.Rot;
            r += 4;
            r %= 4;
            if (r == 0) return new[] { RobotAction.Go };
            if (r == 1) return new[] { RobotAction.Right, RobotAction.Go };
            if (r == 2) return new[] { RobotAction.Left, RobotAction.Left, RobotAction.Go };
            if (r == 3) return new[] { RobotAction.Left, RobotAction.Go };
            throw new Exception("WTF");
        }
Example #2
0
 public void DoExplore(RobotManager r, CancellationToken token)
 {
     var m = r.Map;
     while (!token.IsCancellationRequested)
     {
         var from = (r.Position.GetHashCode() % 5 == 0) ? new Point(0, 0) : r.Position;
         var path = m.NearestNonExploredPointPath(from);
         foreach (var rot in path)
         {
             r.GoTo(rot);
         }
         r.Path.Clear();
         new DfsControler().Execute(r, token, new[] { "500" });
         //r.Map.Save(r.RobotId.ToString());
     }
 }
Example #3
0
 public void DoDfs(RobotManager robot, CancellationToken token, int limit = int.MaxValue)
 {
     try
     {
         var r = robot.Move(RobotAction.Wait);
         while (!token.IsCancellationRequested)
         {
             var s = NextStep(robot, r, limit);
             foreach (var x in s) robot.Move(x);
         }
     }
     catch (MyCoolExceptionForStopingDfsExecution)
     {
         return;
     }
 }
Example #4
0
 private Rotation GetNextStepPoint(RobotManager robot, int limit)
 {
     var a = robot.Position.NearFour();
     var mi = 2;
     var max = 0;
     for (int i = 0; i < a.Length; i++)
     {
         var p = GetPriority(robot.Map, a[i], i);
         if (p >= max)
         {
             max = p;
             mi = i;
         }
     }
     if (max <= 1 || robot.Path.Count >= limit /* ||
         (robot.Map.Explored(robot.Position) && robot.Map[robot.Position] == MapTileResult.OpenDoor)*/)
     {
         if (robot.Path.Count == 0) throw new MyCoolExceptionForStopingDfsExecution();
         return (Rotation)(((byte)robot.Path.Last() + 2) % 4);
     }
     return (Rotation)mi;
 }
Example #5
0
 public void Execute(RobotManager robot, CancellationToken token, string[] args)
 {
     DoExplore(robot, token);
 }
Example #6
0
 public void SetRobotBind(RobotManager robot)
 {
     Robot = robot;
     Robot.Moved += RefreshMapAndPosition;
 }
Example #7
0
 public void Execute(RobotManager robot, CancellationToken token, string[] args)
 {
     DoDfs(robot, token, int.Parse(args.FirstOrDefault() ?? int.MaxValue.ToString()));
 }