Esempio n. 1
0
        public RobotCommand DoStep(IList <Robot.Common.Robot> robots, int robotToMoveIndex, Map map)
        {
            Robot.Common.Robot movingRobot = robots[robotToMoveIndex];

            //CountRobots(robots); //comment when testing

            Position pos = FindNearestFreeStation(movingRobot, map, robots);

            if (DistanceHelper.FindDistance(movingRobot.Position, pos) < 400)
            {
                if (NeedToCreateRobot(movingRobot))
                {
                    return(new CreateNewRobotCommand());
                }
            }

            stationPosition = GetMovePoint(movingRobot, map, robots);

            if (stationPosition == null)
            {
                return(null);
            }

            if (NeedToCollectEnergy(movingRobot, map))
            {
                return(new CollectEnergyCommand());
            }
            else
            {
                return(new MoveCommand()
                {
                    NewPosition = stationPosition
                });
            }
        }
Esempio n. 2
0
        public Position GetMovePoint(Robot.Common.Robot movingRobot,
                                     Map map, IList <Robot.Common.Robot> robots)
        {
            movePoint = FindNearestFreeStation(movingRobot, map, robots);

            for (int i = 0; i < 10; i++)
            {
                if (DistanceHelper.FindDistance(movePoint, movingRobot.Position) <= movingRobot.Energy + minRobotEnergy)
                {
                    return(movePoint);
                }
                else
                {
                    movePoint.X = (movePoint.X + movingRobot.Position.X) / 2;
                    movePoint.Y = (movePoint.Y + movingRobot.Position.Y) / 2;
                }
            }

            return(null);
        }
Esempio n. 3
0
        public Position FindNearestFreeStation(Robot.Common.Robot movingRobot,
                                               Map map, IList <Robot.Common.Robot> robots)
        {
            EnergyStation nearestStation = null;
            int           minDistance    = int.MaxValue;

            foreach (EnergyStation station in map.Stations)
            {
                if (IsStationFree(station, movingRobot, robots))
                {
                    int distance = DistanceHelper.FindDistance(station.Position, movingRobot.Position);

                    if (distance < minDistance)
                    {
                        minDistance    = distance;
                        nearestStation = station;
                    }
                }
            }

            return(nearestStation == null ? null : nearestStation.Position);
        }