Ejemplo n.º 1
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()));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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++]));
 }
Ejemplo n.º 4
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()));
        }
Ejemplo n.º 5
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
            });
        }
Ejemplo n.º 6
0
 private IEnumerable <Command> GoBack()
 {
     return(RobotLocator.GetCommandsByDirection(lastCommand.Invert()).Concat(new[] { Command.Sleep(3) }));
 }
Ejemplo n.º 7
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()));
        }