public ACommand scanProcess(ScanCommand command, Battlefield.RobotAndBattlefield robotAndBattlefield)
        {
            double           minDistance = Battlefield.ARENA_MAX_SIZE * 10;
            BattlefieldRobot robot       = robotAndBattlefield.ROBOT;
            Battlefield      battlefield = robotAndBattlefield.BATTLEFIELD;

            BattlefieldRobot minTarget = robot;

            if (robot.HitPoints > 0)
            {
                foreach (BattlefieldRobot target in battlefield.robots)
                {
                    if (robot.ID != target.ID && target.HitPoints > 0 && battlefield.obstacleManager.CanScan(battlefield.turn, robot.X, robot.Y, target.X, target.Y))
                    {
                        double distance = EuclideanSpaceUtils.Distance(robot.X, robot.Y, target.X, target.Y);
                        if (distance < minDistance)
                        {
                            double degree = AngleUtils.NormalizeDegree(AngleUtils.AngleDegree(robot.X, robot.Y, target.X, target.Y));
                            if (Math.Abs(degree - command.ANGLE) <= command.PRECISION)
                            {
                                minDistance = distance;
                                minTarget   = target;
                            }
                        }
                    }
                }

                battlefield.battlefieldTurn.AddScan(new Scan(command.ANGLE, command.PRECISION, minDistance, robot.X, robot.Y));
            }
            return(new ScanAnswerCommand(minDistance, minTarget.ID));
        }
Esempio n. 2
0
 /// <inheritdoc />
 protected override void afterMovingAndDamaging()
 {
     foreach (var flag in flags)
     {
         FlagPlace flagPlace = flagPlacesById[flag.FROM_FLAGPLACE_ID];
         if (flag.RobotId == 0)
         {
             double minDistance = double.MaxValue;
             foreach (BattlefieldRobot robot in robots)
             {
                 if (robot.TEAM_ID != flagPlace.TEAM_ID)
                 {
                     double distance = EuclideanSpaceUtils.Distance(robot.Position,
                                                                    flagPlace.GetPosition());
                     if (distance < FLAG_PLACE_SIZE && distance < minDistance)
                     {
                         flag.RobotId = robot.ID;
                         minDistance  = distance;
                     }
                 }
             }
         }
         else
         {
             BattlefieldRobot robot;
             if (robotsById.TryGetValue(flag.RobotId, out robot))
             {
                 if (robot.HitPoints <= 0)
                 {
                     flag.RobotId = 0;
                 }
                 else
                 {
                     List <FlagPlace> robotFlagPlaces = flagPlacesByTeamId[robot.TEAM_ID];
                     foreach (var robotFlagPlace in robotFlagPlaces)
                     {
                         double distance = EuclideanSpaceUtils.Distance(robot.Position,
                                                                        robotFlagPlace.GetPosition());
                         if (distance < FLAG_PLACE_SIZE)
                         {
                             foreach (var robotInTeam in robotsByTeamId[robot.TEAM_ID])
                             {
                                 robotInTeam.Score += 10;
                                 flag.RobotId       = 0;
                             }
                             break;
                         }
                     }
                 }
             }
         }
     }
     battlefieldTurn.AddMore(ConvertFlag(flags), POSITION_IN_BATTLE_TURN_FLAG);
     battlefieldTurn.AddMore(flagPlacesById.Values.ToArray(), POSITION_IN_BATTLE_TURN_FLAG_PLACES);
 }
Esempio n. 3
0
 private static RepairmenState getRepairmenState()
 {
     if (
         EuclideanSpaceUtils.Distance(new Point(repairman.X, repairman.Y),
                                      new Point(capturedBase.X, capturedBase.Y)) >
         BaseCapture.BASE_SIZE / 2.0)
     {
         return(RepairmenState.GO_TO_BASE);
     }
     else if (mineLayer.HitPoints < 100 &&
              EuclideanSpaceUtils.Distance(repairman.X, repairman.Y, mineLayer.X, mineLayer.Y) <
              repairman.REPAIR_TOOL.ZONES[0].DISTANCE)
     {
         return(RepairmenState.REPAIR);
     }
     else
     {
         return(RepairmenState.GO_AROUND);
     }
 }
        private ACommand repairProcess(RepairCommand command, Battlefield.RobotAndBattlefield robotAndBattlefield)
        {
            Battlefield battlefield = robotAndBattlefield.BATTLEFIELD;
            Repairman   repairman   = robotAndBattlefield.ROBOT as Repairman;

            if (repairman == null)
            {
                return(new ErrorCommand(robotAndBattlefield.ROBOT.ROBOT_TYPE + " cannot use repair command."));
            }

            if (repairman.RepairToolUsed < repairman.RepairTool.MAX_USAGES && repairman.HitPoints > 0)
            {
                foreach (BattlefieldRobot robot in battlefield.robots)
                {
                    if (robot.HitPoints > 0)
                    {
                        double distance = EuclideanSpaceUtils.Distance(robot.Position,
                                                                       repairman.Position);
                        if (distance < command.MAX_DISTANCE)
                        {
                            Zone zone = Zone.GetZoneByDistance(repairman.RepairTool.ZONES, distance);
                            robot.HitPoints += zone.EFFECT;
                            robot.HitPoints  = Math.Min(robot.HitPoints, robot.Armor.MAX_HP);
                            if (repairman != robot)
                            {
                                repairman.Score += zone.EFFECT;
                            }
                        }

                        battlefield.battlefieldTurn.AddRepair(new ViewerLibrary.Repair(robot.X, robot.Y));
                    }
                }
                repairman.RepairToolUsed++;
                return(new RepairAnswerCommand(true));
            }
            else
            {
                return(new RepairAnswerCommand(false));
            }
        }
Esempio n. 5
0
 private static MinerState getMinerState()
 {
     if (EuclideanSpaceUtils.Distance(new Point(mineLayer.X, mineLayer.Y), new Point(capturedBase.X, capturedBase.Y)) >
         BaseCapture.BASE_SIZE)
     {
         return(MinerState.GO_TO_BASE);
     }
     else if (mineLayer.PutMines < mineLayer.MINE_GUN.MAX_MINES)
     {
         return(MinerState.PUT_MINE);
     }
     else if (mineLayer.HitPoints < mineLayer.previousHitpoints)
     {
         return(MinerState.GO_TO_REPAIRMAN);
     }
     else if (ScanSeeEnemy(scan1) || ScanSeeEnemy(scan2))
     {
         return(MinerState.DETONATE);
     }
     else
     {
         return(MinerState.GO_AROUND);
     }
 }
Esempio n. 6
0
        private void capturingBases()
        {
            foreach (var @base in bases)
            {
                aliveRobotsAtBaseByBase[@base].Clear();
                Dictionary <int, int> progressByTeamId = new Dictionary <int, int>();
                progressByTeamId[@base.ProgressTeamId] = @base.Progress;
                foreach (var robot in getAliveRobots())
                {
                    if (EuclideanSpaceUtils.Distance(new Point(@base.X, @base.Y), new Point(robot.X, robot.Y)) < BASE_SIZE)
                    {
                        aliveRobotsAtBaseByBase[@base].Add(robot);
                        if (@base.TeamId != robot.TEAM_ID)
                        {
                            robot.Score++;
                        }
                        int progressForTeam;
                        if (!progressByTeamId.TryGetValue(robot.TEAM_ID, out progressForTeam))
                        {
                            progressForTeam = 0;
                        }
                        progressForTeam++;
                        progressByTeamId[robot.TEAM_ID] = progressForTeam;
                    }
                }

                int maxTeamProgress = 0;
                int forTeamId       = 0;
                foreach (var teamProgress in progressByTeamId)
                {
                    if (maxTeamProgress < teamProgress.Value)
                    {
                        maxTeamProgress = teamProgress.Value;
                        forTeamId       = teamProgress.Key;
                    }
                }

                int sumOtherProgress = 0;
                foreach (var teamProgress in progressByTeamId)
                {
                    if (teamProgress.Key != forTeamId)
                    {
                        sumOtherProgress += teamProgress.Value;
                    }
                }



                @base.Progress       = maxTeamProgress - sumOtherProgress;
                @base.ProgressTeamId = forTeamId;

                if (@base.Progress <= 0)
                {
                    @base.TeamId = 0;
                }

                @base.Progress = Math.Abs(@base.Progress);
                @base.Progress = Math.Min(@base.Progress, @base.MAX_PROGRESS);

                if (@base.Progress == @base.MAX_PROGRESS)
                {
                    @base.TeamId = @base.ProgressTeamId;
                }
            }
        }
Esempio n. 7
0
        public static void Main(string[] args)
        {
            ClientRobot.Connect(args);
            while (true)
            {
                RepairmenState repairmenState = getRepairmenState();
                MinerState     minerState     = getMinerState();


                switch (minerState)
                {
                case MinerState.DETONATE:
                    if (mineLayer.PutMinesList.Count > 0)
                    {
                        mineLayer.DetonateMine(mineLayer.PutMinesList[0].ID);
                    }
                    break;

                case MinerState.PUT_MINE:
                    mineLayer.PutMine();
                    break;

                case MinerState.GO_TO_REPAIRMAN:
                    mineLayer.Drive(AngleUtils.AngleDegree(mineLayer.X, mineLayer.Y, repairman.X, repairman.Y),
                                    mineLayer.Motor.ROTATE_IN);
                    break;

                case MinerState.GO_TO_BASE:
                    robotDriveToBase(mineLayer);
                    break;

                case MinerState.GO_AROUND:
                    if (EuclideanSpaceUtils.Distance(mineLayer.X, mineLayer.Y, capturedBase.X, capturedBase.Y) < BaseCapture.BASE_SIZE * 3.0 / 4.0)
                    {
                        scan1 = mineLayer.Scan(AngleUtils.AngleDegree(mineLayer.X, mineLayer.Y, capturedBase.X, capturedBase.Y), 10);
                    }
                    else
                    {
                        robotDriveAround(mineLayer);
                    }
                    break;
                }

                switch (repairmenState)
                {
                case RepairmenState.GO_AROUND:
                    if (EuclideanSpaceUtils.Distance(mineLayer.X, mineLayer.Y, capturedBase.X, capturedBase.Y) <
                        BaseCapture.BASE_SIZE * 3.0 / 4.0)
                    {
                        scan2 = repairman.Scan(AngleUtils.AngleDegree(mineLayer.X, mineLayer.Y, capturedBase.X, capturedBase.Y), 10);
                    }
                    else
                    {
                        robotDriveAround(repairman);
                    }
                    break;

                case RepairmenState.GO_TO_BASE:
                    robotDriveToBase(repairman);
                    break;

                case RepairmenState.REPAIR:
                    repairman.Repair((int)EuclideanSpaceUtils.Distance(repairman.X, repairman.Y, mineLayer.X, mineLayer.Y) + 1);
                    break;
                }

                if (repairmenState == RepairmenState.REPAIR)
                {
                    mineLayer.previousHitpoints = mineLayer.HitPoints;
                }
            }
        }