static void Main(string[] args) { ClientRobot.Connect(args); FlagPlace toFlagPlace = null; FlagPlace ownFlagPlace = null; foreach (var flagPlace in flagPlaces) { if (flagPlace.TEAM_ID == tank.TEAM_ID) { ownFlagPlace = flagPlace; } else { toFlagPlace = flagPlace; } } while (true) { if (tank.carryFlag) { driveTo(ownFlagPlace); } else { driveTo(toFlagPlace); } } }
private static void driveTo(FlagPlace place) { double driveAngle = AngleUtils.AngleDegree(tank.X, tank.Y, place.X, place.Y); if (tank.HitPoints == 0) { tank.Wait(); // wait to respawn } if (Math.Abs(driveAngle - tank.AngleDrive) > 5) { if (tank.Power > tank.Motor.ROTATE_IN && tank.WantedPower > tank.Motor.ROTATE_IN) { tank.Drive(driveAngle, tank.Motor.ROTATE_IN); tank.WantedPower = tank.Motor.ROTATE_IN; } else if (tank.Power <= tank.Motor.ROTATE_IN) { tank.Drive(driveAngle, 100); tank.WantedPower = 100; } } for (int angle = 0; angle < 360; angle += 30) { ScanAnswerCommand scanAnswer = tank.Scan(angle, 10); if (scanAnswer.ENEMY_ID != tank.ID) { tank.Shoot(angle, scanAnswer.RANGE); } } }
/// <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); }
private void drawFlagPlace(FlagPlace flagPlace, Graphics g) { if (flagPlace == null) { return; } Pen teamPen = DefaultDrawer.GetTeamPen(flagPlace.TEAM_ID); lock (g) { lock (teamPen) { g.FillEllipse(teamPen.Brush, (float)(flagPlace.X - FLAG_PLACE_SIZE / 2.0), (float)(flagPlace.Y - FLAG_PLACE_SIZE / 2.0), FLAG_PLACE_SIZE, FLAG_PLACE_SIZE); } } }