Esempio n. 1
0
 public override void Initialize(Competitions competitions)
 {
     base.Initialize(competitions);
     Map          = Competitions.GetSensorsData <PositionSensorsData>(ControlledRobot).BuildMap();
     RobotLocator = new RobotLocator(Map);
     enumerator   = currentCommands.GetEnumerator();
 }
Esempio n. 2
0
        private IEnumerable <Command> RepairStarship()
        {
            var nearSocket = Map.Walls.Where(x => x.Type.ToLower().Contains(color)).OrderBy(GetDistance).FirstOrDefault();

            if (nearSocket == null)
            {
                return(new Command[0]);
            }
            var path = PathSearcher.FindPath(Map, OurCoordinates, nearSocket.DiscreteCoordinate);

            if (path.Length == 0)
            {
                if (Map.CurrentPosition.X - nearSocket.AbsoluteCoordinate.X > Epsilon)
                {
                    return(RobotLocator.GetCommandsByDirection(Direction.Left));
                }
                if (Map.CurrentPosition.X - nearSocket.AbsoluteCoordinate.X < -Epsilon)
                {
                    return(RobotLocator.GetCommandsByDirection(Direction.Right));
                }
                if (Map.CurrentPosition.Y - nearSocket.AbsoluteCoordinate.Y > Epsilon)
                {
                    return(RobotLocator.GetCommandsByDirection(Direction.Down));
                }
                if (Map.CurrentPosition.Y - nearSocket.AbsoluteCoordinate.Y < -Epsilon)
                {
                    return(RobotLocator.GetCommandsByDirection(Direction.Up));
                }
                hasDetail = false;
                return(new[] { Command.Act(CommandAction.Release) });
            }
            return(RobotLocator.GetCommandsByDirection(path.First()));
        }
Esempio n. 3
0
        protected override IEnumerable <Command> FindNextCommands()
        {
            var path     = PathSearcher.FindPath(Map, OurCoordinates, OpponentCoordinates);
            var commands = path.Length == 0 ? GoBack() : RobotLocator.GetCommandsByDirection(path.First());

            lastCommand = path.FirstOrDefault();
            return(commands);
        }
Esempio n. 4
0
 protected override IEnumerable <Command> FindNextCommands()
 {
     while (currentCommand >= currentPath.Length)
     {
         var x = random.Next(1, 7);
         var y = random.Next(1, 5);
         currentPath    = PathSearcher.FindPath(Map, OurCoordinates, new Point(x, y));
         currentCommand = 0;
     }
     return(RobotLocator.GetCommandsByDirection(currentPath[currentCommand++]));
 }
Esempio n. 5
0
        private IEnumerable <Command> GripDetail()
        {
            var nearDetail = Map.Details.OrderBy(GetDistance).FirstOrDefault();

            if (nearDetail == null)
            {
                return(new Command[0]);
            }
            color = nearDetail.Type.Split(new[] { "Detail" }, StringSplitOptions.None).First().ToLower();
            var path = PathSearcher.FindPath(Map, OurCoordinates, nearDetail.DiscreteCoordinate);

            hasDetail = path.Length == 0;
            return(hasDetail ? new[] { Command.Act(CommandAction.Grip) } : RobotLocator.GetCommandsByDirection(path.First()));
        }
Esempio n. 6
0
        private static void Main(string[] args)
        {
            var server       = new CvarcClient(args, Settings).GetServer <PositionSensorsData>();
            var sensorData   = server.Run().SensorsData;
            var map          = sensorData.BuildMap();
            var robotLocator = new RobotLocator(map);
            var path         = PathSearcher.FindPath(map, map.GetDiscretePosition(map.CurrentPosition), new Point(2, 1));//(2, 1) - just random point

            foreach (var direction in path)
            {
                foreach (var command in robotLocator.GetCommandsByDirection(direction))
                {
                    sensorData = server.SendCommand(command);
                    robotLocator.Update(sensorData);
                }
            }
            server.SendCommand(new Command {
                Action = CommandAction.WaitForExit
            });
        }
Esempio n. 7
0
 private IEnumerable <Command> GoBack()
 {
     return(RobotLocator.GetCommandsByDirection(lastCommand.Invert()).Concat(new[] { Command.Sleep(3) }));
 }
Esempio n. 8
0
        protected override IEnumerable <Command> FindNextCommands()
        {
            var path = PathSearcher.FindPath(Map, OurCoordinates, OpponentCoordinates);

            return(path.Length == 0 || path.Length == 1 ? new Command[0] : RobotLocator.GetCommandsByDirection(path.First()));
        }