Example #1
0
        public RobotCommand DoStep(IList <Robot> robots, int robotToMoveIndex, Map map)
        {
            FileLogger.Log("\n\nMY MOVE\n\n");

            Robot myRobot = robots[robotToMoveIndex];

            if (CanClone(myRobot))
            {
                FileLogger.Log("Decided to clone");
                robotsCount++;
                return(new CreateNewRobotCommand());
            }

            RoundData data = new RoundData(map, robots, myRobot);

            ResolvedProfit <EnergyStation> bestStation = FindMostProfitableItem(data, stationProfitResolver);
            ResolvedProfit <Robot>         bestRobot   = FindMostProfitableItem(data, robotProfitResolver);

            FileLogger.Log($"Round {currentRound}, Robot #{robotToMoveIndex} - {myRobot.Format()}");
            FileLogger.Log($"Best station: {bestStation.Item.Format()} with profit {bestStation.Profit}");
            FileLogger.Log($"Best robot: {bestRobot.Item.Format()} with profit {bestRobot.Profit}");

            if (bestStation == null && bestRobot == null)
            {
                return new MoveCommand()
                       {
                           NewPosition = data.MyPosition
                       }
            }
            ;

            int accessibleEnergy = ResolveAccessibleStationEnergy(data.MyPosition, data.Map.Stations);

            if (accessibleEnergy > bestStation?.Profit?.Profit && accessibleEnergy > bestRobot?.Profit?.Profit)
            {
                FileLogger.Log("Decided to collect energy now");

                return(new CollectEnergyCommand());
            }

            if (bestStation?.Profit?.CompareTo(bestRobot.Profit) > 0)
            {
                FileLogger.Log("Decided to work with station");
                return(stationProfitResolver.ProcessStep(data, bestStation.Item, bestStation.Profit));
            }
            else
            {
                FileLogger.Log("Decided to work with robot");
                return(robotProfitResolver.ProcessStep(data, bestRobot.Item, bestRobot.Profit));
            }
        }
 public RobotCommand ProcessStep(RoundData data, EnergyStation station, ProfitData profit)
 {
     if (DistanceUtils.DistanceFromStation(data.MyPosition, station.Position) <= Constants.CollectingRadius)
     {
         FileLogger.Log("Collecting energy from stations nearby");
         return(new CollectEnergyCommand());
     }
     else
     {
         FileLogger.Log($"Moving to station {station.Format()} at position {profit.MovePosition}");
         return(new MoveCommand()
         {
             NewPosition = profit.MovePosition
         });
     }
 }
        public RobotCommand ProcessStep(RoundData data, Robot robot, ProfitData profit)
        {
            if (data.MyPosition == robot.Position)
            {
                FileLogger.Log($"Attacking robot: {robot.Format()} at position {profit.MovePosition}");
            }
            else
            {
                FileLogger.Log($"Moving to robot {robot} at position {profit.MovePosition}");
            }

            return(new MoveCommand()
            {
                NewPosition = profit.MovePosition
            });
        }
        public ProfitData CalculateProfit(RoundData data, EnergyStation station)
        {
            float distance = DistanceUtils.DistanceBetweenPoints(data.MyPosition, station.Position);

            KeyValuePair <float, int> bestStepDistanceToProfit = AverageStepDistances.ToDictionary(
                stepDitance => stepDitance,
                stepDistance => ResolveProfitWithAverageStepDistance(station, distance, stepDistance)
                )
                                                                 .ToList()
                                                                 .MaxBy(entry => entry.Value);

            float averageStepDistance = bestStepDistanceToProfit.Key;
            int   stepsCount          = (int)Math.Ceiling(distance / averageStepDistance);

            if (stepsCount == 0)
            {
                stepsCount = 1;
            }

            int profit = bestStepDistanceToProfit.Value;

            Position positionToCollectEnergy = PositionHelper.FindNearestStationPositon(
                data.MyPosition,
                station.Position,
                data.Robots.FilterForeignRobots()
                );
            Position movePosition;

            if (positionToCollectEnergy == null)
            {
                movePosition = data.MyPosition;
            }
            else
            {
                movePosition = DistanceUtils.ResolveMovePosition(
                    data.MyPosition,
                    positionToCollectEnergy,
                    stepsCount,
                    data.Map,
                    data.Robots
                    );
            }

            if (movePosition == null)
            {
                FileLogger.Log("Failed to find move position");
                movePosition = data.MyPosition;
            }

            float moveDistance = DistanceUtils.DistanceBetweenPoints(data.MyPosition, movePosition);
            float maxMoveDistanceWithDisplacement = distance / stepsCount + Constants.MaxMovementDisplacement;

            if (moveDistance > maxMoveDistanceWithDisplacement && movePosition != positionToCollectEnergy)
            {
                FileLogger.Log("Availabel move position is too far");
                movePosition = data.MyPosition;
            }

            return(new ProfitData(
                       profit - DistanceUtils.ResolveMoveEnergy(data.MyPosition, station.Position, stepsCount, data.Map, data.Robots),
                       distance,
                       stepsCount,
                       movePosition
                       ));
        }
Example #5
0
        // TODO taret stations and robots

        public AndriiShpekAlgorithm()
        {
            Logger.OnLogRound   += (s, e) => currentRound++;
            Logger.OnLogMessage += (s, e) => FileLogger.Log($"{e.OwnerName} --- {e.Message}");
        }