Example #1
0
 public static void loop(RobotController theRC) throws GameActionException {
   Clock.yield();
   Bot.init(theRC);
   init();
   while (true) {
     try {
       turn();
     } catch (Exception e) {
       e.printStackTrace();
     }
     Clock.yield();
   }
 }
Example #2
0
 /**
  * 1) process signals, try to find turtleCorner 2) if enemies are within sensing radius, unpack 3)
  * if too close to archons, move away 4) if too close to wall, move away 5) if too close to
  * corner, move away 6) if it did nothing, unpack
  *
  * @param rc
  */
 private static void ttm(RobotController rc) {
   turtleCorner = turtleCorner.equals(null) ? LOCATION_NONE : turtleCorner;
   try {
     RobotInfo[] friendlyRobots =
         rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, rc.getTeam());
     if (rc.getHealth() <= 3 && rc.isInfected() && friendlyRobots.length > 0) {
       rc.disintegrate();
     }
     // 1)
     if (isNearbyEnemies(rc) && rc.isCoreReady()) {
       rc.unpack();
     }
     // 2)
     processFighterSignals(rc);
     // 3)
     moveAwayFromArchons(rc);
     // 4)
     moveAwayFromWalls(rc);
     // 5)
     if (turtleCorner != LOCATION_NONE) moveFromCorner(rc);
     // 6)
     if (rc.isCoreReady() && rc.getType() == RobotType.TTM && rc.getRoundNum() % 25 == 0)
       rc.unpack();
     rc.setIndicatorString(0, "Turtle x: " + turtleCorner.x + "Turtle y: " + turtleCorner.y);
     rc.setIndicatorString(1, "I am a TTM!");
     Clock.yield();
   } catch (GameActionException e) {
     e.printStackTrace();
   }
 }
  public static void yield() {
    if (my_type == RobotType.ARCHON) rc.setIndicatorString(0, "Beta 1.5");

    if (rc.getRoundNum() % 25 == 0) Scanner.reset_health();

    Clock.yield();
  }
Example #4
0
 private static void turret(RobotController rc) {
   // do one time things here
   turtleCorner = turtleCorner == null ? LOCATION_NONE : turtleCorner;
   try {
     RobotInfo[] friendlyRobots =
         rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, rc.getTeam());
     if (rc.getHealth() <= 3 && rc.isInfected() && friendlyRobots.length > 0) {
       rc.disintegrate();
     }
     turretAttack(rc);
     processFighterSignals(rc);
     if ((archonIsTooClose(rc) || isAdjacentToWall(rc))
         && rc.getType() == RobotType.TURRET
         && rc.isCoreReady()) {
       rc.pack();
     }
     if (turtleCorner != LOCATION_NONE && rc.isCoreReady() && rc.getType() == RobotType.TURRET) {
       int minCornerRadius = (20 + (rc.getRobotCount() / 10));
       if (rc.getLocation().distanceSquaredTo(turtleCorner) < minCornerRadius) {
         rc.pack();
       }
     }
     rc.setIndicatorString(0, "Turtle x: " + turtleCorner.x + "Turtle y: " + turtleCorner.y);
     rc.setIndicatorString(1, "I am a turret");
     // if (turtleCorner.equals(LOCATION_NONE)) tryToLocateCorner(rc);
     Clock.yield();
   } catch (GameActionException e) {
     e.printStackTrace();
   }
 }
Example #5
0
 /**
  * Working on soldier behavior: 1) If about to die and infected and senses nearby friendly robots,
  * self destruct 2) Attack if possible 3) Process signals. (If another soldier signals, move
  * towards that soldier (means there is a zombie den nearby)) 4) Move away from walls / archons 5)
  * Use position and relative position to turtle corner to move away or toward turtle corner 6) Try
  * to clear surrounding rubble
  *
  * @param rc
  */
 private static void soldier(RobotController rc) {
   turtleCorner = LOCATION_NONE;
   while (true) {
     try {
       // 1)
       RobotInfo[] friendlyRobots =
           rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, rc.getTeam());
       if (rc.getHealth() <= 3 && rc.isInfected() && friendlyRobots.length > 0) {
         rc.disintegrate();
       } else {
         // 2)
         attackFirst(rc);
         // 3)
         processFighterSignals(rc);
         // 4)
         moveAwayFromArchons(rc);
         moveAwayFromWalls(rc);
         // 5)
         if (!turtleCorner.equals(LOCATION_NONE)) {
           moveFromCorner(rc);
         } else if (currentMode == TRANSITION_MODE) {
           moveTowardsArchon(rc);
         }
         // 6)
         clearRubble(rc);
         //					if(turtleCorner.equals(LOCATION_NONE)) tryToLocateCorner(rc);
       }
       rc.setIndicatorString(0, "Turtle x: " + turtleCorner.x + "Turtle y: " + turtleCorner.y);
       rc.setIndicatorString(1, "Current Mode" + currentMode);
       Clock.yield();
     } catch (GameActionException e) {
       e.printStackTrace();
     }
   }
 }
Example #6
0
 private static void viper(RobotController rc) {
   // in case we use vipers later
   // do one time things here
   while (true) {
     rc.disintegrate();
     Clock.yield();
   }
 }
Example #7
0
 ///////////////////////////////////////////////////////////
 // moveClear()
 //
 private static void moveClear() throws GameActionException {
   while (true) {
     MapLocation center = closestArchonLoc();
     if (rc.getLocation().distanceSquaredTo(center) >= guardRad) break;
     else {
       if (!moveAway(center)) break;
     }
   }
   rc.unpack();
   Clock.yield();
 }
Example #8
0
 public static void run(RobotController _rc) throws GameActionException {
   Bot.init(_rc);
   init();
   while (true) {
     myLocation = rc.getLocation();
     Radio.process();
     action();
     Radio.clear();
     Clock.yield();
   }
 }
Example #9
0
 public void run() {
   while (true) {
     try {
       currentLocation = rc.getLocation();
       roundNumber = rc.getRoundNum();
       doTurn();
       Clock.yield();
     } catch (GameActionException e) {
       System.out.println(e.getMessage());
       e.printStackTrace();
     }
   }
 }
Example #10
0
 /////////////////////////////////////////////////////////////
 // moveAway()
 //
 private static boolean moveAway(MapLocation center) throws GameActionException {
   while (!rc.isCoreReady()) {
     Clock.yield();
   }
   Direction dir = center.directionTo(rc.getLocation());
   int c = 0;
   while (!rc.canMove(dir)) {
     dir = dir.rotateRight();
     c++;
     if (c >= 4) return false;
   }
   rc.move(dir);
   return true;
 }
Example #11
0
 private static void guard(RobotController rc) {
   // do one time things here
   while (true) {
     try {
       if (currentMode == INTRO_MODE) {
         // TODO smarter attacking (make a method to pick and attack, move if appropriate)
         if (rc.isWeaponReady()) attackFirst(rc);
         if (rc.isCoreReady()) {
           // so that you don't try to move and get delay if you should be getting ready to attack
           moveTowardsNearestEnemy(rc);
         }
       }
       Clock.yield();
     } catch (GameActionException e) {
       e.printStackTrace();
     }
   }
 }
  public void run(final RobotController robotController) throws GameActionException {

    final MapInfoModule mapInfoModule = new MapInfoModule();

    final CombatModule combatModule = new CombatModule();
    final CommunicationModule communicationModule = new CommunicationModule(mapInfoModule);
    final DirectionModule directionModule = new DirectionModule(robotController.getID());
    final MovementModule movementModule = new MovementModule();
    final RubbleModule rubbleModule = new RubbleModule();

    final Team currentTeam = robotController.getTeam();
    int turnsStuck = 0;

    while (true) {

      RobotType type = robotController.getType();
      MapLocation currentLocation = robotController.getLocation();

      // update communication

      communicationModule.processIncomingSignals(robotController);

      // let's verify existing information

      communicationModule.verifyCommunicationsInformation(robotController, null, false);

      if (type == RobotType.TTM) {

        // MOVE

        // let's get the best assignment

        CommunicationModuleSignal objectiveSignal = null;
        int closestObjectiveLocationDistance = Integer.MAX_VALUE;

        final Enumeration<CommunicationModuleSignal> zombieDenCommunicationModuleSignals =
            communicationModule.zombieDens.elements();
        while (zombieDenCommunicationModuleSignals.hasMoreElements()) {

          final CommunicationModuleSignal signal =
              zombieDenCommunicationModuleSignals.nextElement();
          final int distance = signal.location.distanceSquaredTo(currentLocation);
          if (distance < closestObjectiveLocationDistance) {

            objectiveSignal = signal;
            closestObjectiveLocationDistance = distance;
          }
        }

        final Enumeration<CommunicationModuleSignal> enemyArchonCommunicationModuleSignals =
            communicationModule.enemyArchons.elements();
        while (enemyArchonCommunicationModuleSignals.hasMoreElements()) {

          final CommunicationModuleSignal signal =
              enemyArchonCommunicationModuleSignals.nextElement();
          final int distance =
              signal.location.distanceSquaredTo(currentLocation)
                  * 6; // multiplying by 6 to prioritize the dens
          if (distance < closestObjectiveLocationDistance) {

            objectiveSignal = signal;
            closestObjectiveLocationDistance = distance;
          }
        }

        final Enumeration<CommunicationModuleSignal> enemyTurretCommunicationModuleSignals =
            communicationModule.enemyTurrets.elements();
        while (enemyTurretCommunicationModuleSignals.hasMoreElements()) {

          final CommunicationModuleSignal signal =
              enemyTurretCommunicationModuleSignals.nextElement();
          final int distance = signal.location.distanceSquaredTo(currentLocation) * 20;
          if (distance < closestObjectiveLocationDistance) {

            objectiveSignal = signal;
            closestObjectiveLocationDistance = distance;
          }
        }

        boolean shouldMove = true;
        Direction desiredMovementDirection = null;
        Direction targetRubbleClearanceDirection = null;

        // check to make sure we are safe

        final RobotInfo[] enemies =
            robotController.senseHostileRobots(
                currentLocation, robotController.getType().sensorRadiusSquared);

        if (robotController.isCoreReady() && enemies.length > 0) {

          final Direction fleeDirection =
              directionModule.averageDirectionTowardDangerousRobotsAndOuterBounds(
                  robotController, enemies);
          if (fleeDirection != null) {

            final Direction fleeMovementDirection =
                directionModule.recommendedMovementDirectionForDirection(
                    fleeDirection.opposite(), robotController, false);
            if (fleeMovementDirection != null) {

              robotController.move(fleeMovementDirection);
              currentLocation = robotController.getLocation();
              robotController.setIndicatorString(
                  1, fleeDirection.name() + " " + fleeMovementDirection.name());
            }
          }
        }

        // check if there are nearby signals

        if (desiredMovementDirection == null) {

          int closestSignalDistance = Integer.MAX_VALUE;
          MapLocation closestSignalLocation = null;

          final ArrayList<Signal> notifications = communicationModule.notifications;
          for (int i = 0; i < notifications.size(); i++) {

            final Signal signal = notifications.get(i);
            final int distance = currentLocation.distanceSquaredTo(signal.getLocation());
            if (distance < closestSignalDistance) {

              closestSignalDistance = distance;
              closestSignalLocation = signal.getLocation();
            }
          }
          if (closestSignalLocation != null) {

            desiredMovementDirection = currentLocation.directionTo(closestSignalLocation);
          }
        }

        // now let's try move toward an assignment

        if (robotController.isCoreReady()
            && communicationModule.initialInformationReceived
            && shouldMove) {

          // check if we have an objective

          if (desiredMovementDirection == null) {

            if (objectiveSignal != null) {

              final MapLocation objectiveLocation = objectiveSignal.location;
              if (objectiveLocation.distanceSquaredTo(currentLocation) >= 8) {

                desiredMovementDirection = currentLocation.directionTo(objectiveLocation);
              }
            }
          }

          // try move towards archon starting positions

          if (desiredMovementDirection == null) {

            int closestArchonDistance = Integer.MAX_VALUE;
            MapLocation closestArchonLocation = null;

            final MapLocation[] archonLocations =
                robotController.getInitialArchonLocations(robotController.getTeam().opponent());
            for (int i = 0; i < archonLocations.length; i++) {

              final MapLocation location = archonLocations[i];
              final int distance = currentLocation.distanceSquaredTo(location);
              if (distance < closestArchonDistance) {

                closestArchonDistance = distance;
                closestArchonLocation = location;
              }
            }
            if (closestArchonLocation != null) {

              desiredMovementDirection = currentLocation.directionTo(closestArchonLocation);
            }
          }

          // process movement

          if (desiredMovementDirection != null) {

            final Direction recommendedMovementDirection =
                directionModule.recommendedMovementDirectionForDirection(
                    desiredMovementDirection, robotController, false);
            final MapLocation recommendedMovementLocation =
                recommendedMovementDirection != null
                    ? currentLocation.add(recommendedMovementDirection)
                    : null;
            if (recommendedMovementDirection != null
                && !movementModule.isMovementLocationRepetitive(
                    recommendedMovementLocation, robotController)) {

              robotController.move(recommendedMovementDirection);
              movementModule.addMovementLocation(recommendedMovementLocation, robotController);
              currentLocation = robotController.getLocation();
              turnsStuck = 0;
            }
          }
        }

        // unpack if we're safe

        RobotInfo[] nearbyTeammates = robotController.senseNearbyRobots(8, currentTeam);
        RobotInfo[] nearbySoldiers =
            combatModule.robotsOfTypesFromRobots(
                nearbyTeammates, new RobotType[] {RobotType.SOLDIER});

        if (nearbySoldiers.length > 2) {

          robotController.unpack();
        }

      } else {

        // ATTACK

        final RobotInfo[] enemies =
            robotController.senseHostileRobots(
                currentLocation, robotController.getType().attackRadiusSquared);

        RobotInfo bestEnemy = this.getBestEnemyToAttackFromEnemies(robotController, enemies);

        // handle attacking

        if (bestEnemy != null) {

          if (robotController.isWeaponReady()) {

            // we can attack the enemy

            robotController.attackLocation(bestEnemy.location);
            if (bestEnemy.type != RobotType.ZOMBIEDEN) {

              communicationModule.broadcastSignal(
                  robotController,
                  CommunicationModule.maximumFreeBroadcastRangeForRobotType(
                      robotController.getType()));
            }
          }
        }

        // pack if we aren't near soldiers

        RobotInfo[] nearbyTeammates =
            robotController.senseNearbyRobots(type.sensorRadiusSquared, currentTeam);
        RobotInfo[] nearbySoldiers =
            combatModule.robotsOfTypesFromRobots(
                nearbyTeammates, new RobotType[] {RobotType.SOLDIER});

        if (nearbySoldiers.length < 3) {

          robotController.pack();
        }
      }

      Clock.yield();
    }
  }
Example #13
0
  public static void run(RobotController rc) {
    Random rand = new Random(rc.getID());
    Team myTeam = rc.getTeam();
    Team enemyTeam = myTeam.opponent();
    int numFriendly = 0;
    RobotInfo[] adjNeutralRobots = rc.senseNearbyRobots(2, Team.NEUTRAL);
    // if useTurrets = true, then use turret strategy
    boolean useTurrets = false;

    try {
      // Any code here gets executed exactly once at the beginning of the game.
      RobotInfo[] nearbyArchons =
          rc.senseNearbyRobots(RobotType.ARCHON.sensorRadiusSquared, rc.getTeam());
      if (nearbyArchons.length >= 2) {
        useTurrets = true;
      }
      // rc.setIndicatorString(1, "newString");
    } catch (Exception e) {
      // Throwing an uncaught exception makes the robot die, so we need to catch exceptions.
      // Caught exceptions will result in a bytecode penalty.
      System.out.println(e.getMessage());
      e.printStackTrace();
    }

    while (true) {
      // This is a loop to prevent the run() method from returning. Because of the Clock.yield()
      // at the end of it, the loop will iterate once per game round.
      try {
        if (useTurrets) {
          boolean escape = false;
          //					if (rc.isCoreReady()) {
          //						int numAdjTurrets = 0;
          //						for (RobotInfo f : friendlyAdjacent) {
          //							if (f.type == RobotType.TURRET) {
          //								numAdjTurrets++;
          //							}
          //						}
          //						if (numAdjTurrets < 3) {
          //							escape = Movement.moveAwayFromEnemy(rc);
          //						}
          //					}
          //					if (rc.isCoreReady()) {
          //						escape = Movement.moveAwayFromEnemy(rc);
          //					}
          if (!escape) {
            if (adjNeutralRobots.length > 0) {
              // if there is a neutral robot adjacent, activate it or wait until there's no core
              // delay
              if (rc.isCoreReady()) {
                rc.activate(adjNeutralRobots[0].location);
              }
            }
            // careful- moving to parts might get into enemy turret range
            if (Movement.getToAdjParts(rc)) {
            } else {
              boolean toheal = false;
              // repair a nearby friendly robot
              if (rc.isWeaponReady()) {
                RobotInfo[] friendlyWithinRange = rc.senseNearbyRobots(24, myTeam);
                numFriendly = friendlyWithinRange.length;
                if (friendlyWithinRange.length > 0) {
                  RobotInfo toRepair = friendlyWithinRange[0];
                  for (RobotInfo r : friendlyWithinRange) {
                    if ((r.health < toRepair.health)
                        && (r.type != RobotType.ARCHON)
                        && (r.maxHealth - r.health > 1)) {
                      toRepair = r;
                    }
                  }
                  if ((toRepair.maxHealth - toRepair.health > 1)
                      && (toRepair.type != RobotType.ARCHON)) {
                    toheal = true;
                    rc.repair(toRepair.location);
                  }
                }
              }
              if (toheal == false && rc.isCoreReady()) {
                // did not heal any robots

                // sense all the hostile robots within the archon's radius
                MapLocation myLoc = rc.getLocation();
                RobotInfo[] hostileWithinRange =
                    rc.senseHostileRobots(myLoc, RobotType.ARCHON.sensorRadiusSquared);
                RobotInfo closestRobot = null;
                int closestDistance = 0;
                // get the furthest robot from the scout
                for (RobotInfo r : hostileWithinRange) {
                  if (r.location.distanceSquaredTo(myLoc) > closestDistance) {
                    closestRobot = r;
                    closestDistance = r.location.distanceSquaredTo(myLoc);
                  }
                }
                // if there is such an enemy, signal it to range 8
                if (closestRobot != null) {
                  try {
                    // this signaling is only effective against non turret enemies
                    rc.broadcastMessageSignal(closestRobot.location.x, closestRobot.location.y, 8);
                  } catch (GameActionException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  }
                }

                int turnNum = rc.getRoundNum();
                int numVeryCloseScouts = 0;
                int numNearbyTurrets = 0;
                RobotInfo[] friendlyNearby =
                    rc.senseNearbyRobots(RobotType.ARCHON.sensorRadiusSquared, myTeam);
                for (RobotInfo f : friendlyNearby) {
                  if (f.type == RobotType.TURRET) {
                    numNearbyTurrets++;
                  }
                }
                // for sensing if there are guards within range 24
                RobotInfo[] friendlyClose = rc.senseNearbyRobots(24, myTeam);
                int numNearbyGuards = 0;
                for (RobotInfo f : friendlyClose) {
                  if (f.type == RobotType.GUARD) {
                    numNearbyGuards++;
                  }
                }
                // check for scouts; how close should they be????
                RobotInfo[] friendlyVeryClose = rc.senseNearbyRobots(15, myTeam);
                for (RobotInfo f : friendlyClose) {
                  if (f.type == RobotType.SCOUT) {
                    numVeryCloseScouts++;
                  }
                }
                if (rc.hasBuildRequirements(RobotType.GUARD)
                    && rc.isCoreReady()
                    && numNearbyGuards < 1) {
                  Direction dirToBuild = RobotPlayer.directions[rand.nextInt(8)];
                  for (int i = 0; i < 8; i++) {
                    // If possible, build in this direction
                    if (rc.canBuild(dirToBuild, RobotType.GUARD)) {
                      rc.build(dirToBuild, RobotType.GUARD);
                      break;
                    } else {
                      // Rotate the direction to try
                      dirToBuild = dirToBuild.rotateLeft();
                    }
                  }
                }
                // if there are <1 turrets next to archon, build asap
                if (rc.hasBuildRequirements(RobotType.TURRET)
                    && rc.isCoreReady()
                    && numNearbyTurrets < 1) {
                  Direction dirToBuild = RobotPlayer.directions[rand.nextInt(4) * 2];
                  for (int i = 0; i < 4; i++) {
                    // If possible, build in this direction
                    if (rc.canBuild(dirToBuild, RobotType.TURRET)) {
                      rc.build(dirToBuild, RobotType.TURRET);
                      turretCount++;
                      break;
                    } else {
                      // Rotate the direction to try
                      dirToBuild = dirToBuild.rotateLeft();
                      dirToBuild = dirToBuild.rotateLeft();
                    }
                  }
                }
                // if there are <1 scout next to archon and 1 turret, build scout asap
                if (rc.hasBuildRequirements(RobotType.SCOUT)
                    && rc.isCoreReady()
                    && numNearbyTurrets > 0
                    && numVeryCloseScouts == 0
                    && turnNum < 400) {
                  Direction dirToBuild = RobotPlayer.directions[rand.nextInt(8)];
                  for (int i = 0; i < 8; i++) {
                    // If possible, build in this direction
                    if (rc.canBuild(dirToBuild, RobotType.SCOUT)) {
                      rc.build(dirToBuild, RobotType.SCOUT);
                      scoutCount++;
                      break;
                    } else {
                      // Rotate the direction to try
                      dirToBuild = dirToBuild.rotateLeft();
                    }
                  }
                }
                // build turret every 100 turns until turn 400
                //								if (turnNum > 1 && turnNum < 400) {
                //									if (turnNum % 100 == 85 && rc.isCoreReady()) {
                //										Direction dirToBuild = RobotPlayer.directions[rand.nextInt(4)*2];
                //										for (int i = 0; i < 4; i++) {
                //											// If possible, build in this direction
                //											if (rc.canBuild(dirToBuild, RobotType.TURRET)) {
                //												rc.build(dirToBuild, RobotType.TURRET);
                //												turretCount++;
                //												break;
                //											} else {
                //												// Rotate the direction to try
                //												dirToBuild = dirToBuild.rotateLeft();
                //												dirToBuild = dirToBuild.rotateLeft();
                //											}
                //										}
                //									}
                //								}
                else {
                  // Check if this ARCHON's core is ready
                  if (rc.isCoreReady()) {
                    boolean built = false;
                    RobotType typeToBuild = RobotType.TURRET;
                    if (scoutCount < turretCount / 5) {
                      typeToBuild = RobotType.SCOUT;
                    }
                    // never build scouts after a certain turn
                    if (turnNum < 1500) {
                      typeToBuild = RobotType.TURRET;
                    }
                    // Check for sufficient parts
                    if (rc.hasBuildRequirements(typeToBuild)) {
                      // Choose a random direction to try to build in; NESW for turrets; all 8 for
                      // scouts
                      if (typeToBuild.equals(RobotType.TURRET)) {
                        Direction dirToBuild = RobotPlayer.directions[rand.nextInt(4) * 2];
                        for (int i = 0; i < 4; i++) {
                          // If possible, build in this direction
                          if (rc.canBuild(dirToBuild, RobotType.TURRET)) {
                            rc.build(dirToBuild, RobotType.TURRET);
                            turretCount++;
                            break;
                          } else {
                            // Rotate the direction to try
                            dirToBuild = dirToBuild.rotateLeft();
                            dirToBuild = dirToBuild.rotateLeft();
                          }
                        }
                      } else {
                        Direction dirToBuild = RobotPlayer.directions[rand.nextInt(8)];
                        for (int i = 0; i < 8; i++) {
                          // If possible, build in this direction
                          if (rc.canBuild(dirToBuild, RobotType.SCOUT)) {
                            rc.build(dirToBuild, RobotType.SCOUT);
                            scoutCount++;
                            break;
                          } else {
                            // Rotate the direction to try
                            dirToBuild = dirToBuild.rotateLeft();
                          }
                        }
                      }
                    }
                    // only move around if there are resources
                    if ((!built)
                        && rc.hasBuildRequirements(RobotType.TURRET)
                        && (rc.isCoreReady())) {
                      // don't move into enemy turret range if scout sends signal about it
                      Set<Direction> dangerousDirs = new HashSet<>();
                      Signal currentSignal = rc.readSignal();
                      while (currentSignal != null) {
                        int messageX = currentSignal.getMessage()[0];
                        int messageY = currentSignal.getMessage()[1];
                        // if signal message > 80000, then the message is signaling a turret
                        // location
                        if (messageX > 80000) {
                          messageX = messageX - 100000;
                          messageY = messageY - 100000;
                          MapLocation enemyTurretLoc = new MapLocation(messageX, messageY);
                          Direction dirToEnemyTurret = myLoc.directionTo(enemyTurretLoc);
                          Direction dirToEnemyTurretL =
                              myLoc.directionTo(enemyTurretLoc).rotateLeft();
                          Direction dirToEnemyTurretR =
                              myLoc.directionTo(enemyTurretLoc).rotateRight();
                          if (myLoc.add(dirToEnemyTurret).distanceSquaredTo(enemyTurretLoc) <= 48) {
                            dangerousDirs.add(dirToEnemyTurret);
                          }
                          if (myLoc.add(dirToEnemyTurretL).distanceSquaredTo(enemyTurretLoc)
                              <= 48) {
                            dangerousDirs.add(dirToEnemyTurretL);
                          }
                          if (myLoc.add(dirToEnemyTurretR).distanceSquaredTo(enemyTurretLoc)
                              <= 48) {
                            dangerousDirs.add(dirToEnemyTurretR);
                          }
                        }
                        currentSignal = rc.readSignal();
                      }

                      Direction dirToMove = RobotPlayer.directions[(rand.nextInt(4) * 2) + 1];
                      for (int i = 0; i < 4; i++) {
                        if (rc.canMove(dirToMove) && !dangerousDirs.contains(dirToMove)) {
                          rc.move(dirToMove);
                          break;
                        } else {
                          dirToMove = dirToMove.rotateLeft();
                          dirToMove = dirToMove.rotateLeft();
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        } else { // use soldiers
          boolean escape = false;
          if (rc.isCoreReady()) {
            escape = Movement.moveAwayFromEnemy(rc);
          }
          if (!escape) {
            if (adjNeutralRobots.length > 0) {
              // if there is a neutral robot adjacent, activate it or wait until there's no core
              // delay
              if (rc.isCoreReady()) {
                rc.activate(adjNeutralRobots[0].location);
              }
            }
            if (Movement.getToAdjParts(rc)) {
            } else {
              boolean toheal = false;
              // repair a nearby friendly robot
              if (rc.isWeaponReady()) {
                RobotInfo[] friendlyWithinRange = rc.senseNearbyRobots(24, myTeam);
                numFriendly = friendlyWithinRange.length;
                if (friendlyWithinRange.length > 0) {
                  RobotInfo toRepair = friendlyWithinRange[0];
                  for (RobotInfo r : friendlyWithinRange) {
                    if ((r.health < toRepair.health)
                        && (r.type != RobotType.ARCHON)
                        && (r.maxHealth - r.health > 1)) {
                      toRepair = r;
                    }
                  }
                  if ((toRepair.maxHealth - toRepair.health > 1)
                      && (toRepair.type != RobotType.ARCHON)) {
                    toheal = true;
                    rc.repair(toRepair.location);
                  }
                }
              }
              if (toheal == false) {
                // for sensing if there are guards within range 24
                RobotInfo[] friendlyClose = rc.senseNearbyRobots(24, myTeam);
                int numNearbyGuards = 0;
                for (RobotInfo f : friendlyClose) {
                  if (f.type == RobotType.GUARD) {
                    numNearbyGuards++;
                  }
                }

                boolean built = false;
                int turnNum = rc.getRoundNum();
                if (rc.hasBuildRequirements(RobotType.SCOUT)
                    && rc.isCoreReady()
                    && turnNum > 1
                    && turnNum % 150 >= 0
                    && turnNum % 150 <= 19
                    && turnNum < 900) {
                  Direction dirToBuild = RobotPlayer.directions[rand.nextInt(8)];
                  for (int i = 0; i < 8; i++) {
                    // If possible, build in this direction
                    if (rc.canBuild(dirToBuild, RobotType.SCOUT)) {
                      rc.build(dirToBuild, RobotType.SCOUT);
                      built = true;
                      break;
                    } else {
                      // Rotate the direction to try
                      dirToBuild = dirToBuild.rotateLeft();
                    }
                  }
                }
                if (rc.hasBuildRequirements(RobotType.GUARD)
                    && rc.isCoreReady()
                    && !built
                    && numNearbyGuards < 1) {
                  Direction dirToBuild = RobotPlayer.directions[rand.nextInt(8)];
                  for (int i = 0; i < 8; i++) {
                    // If possible, build in this direction
                    if (rc.canBuild(dirToBuild, RobotType.GUARD)) {
                      rc.build(dirToBuild, RobotType.GUARD);
                      built = true;
                      break;
                    } else {
                      // Rotate the direction to try
                      dirToBuild = dirToBuild.rotateLeft();
                    }
                  }
                }
                if (rc.hasBuildRequirements(RobotType.SOLDIER) && rc.isCoreReady() && !built) {
                  Direction dirToBuild = RobotPlayer.directions[rand.nextInt(8)];
                  for (int i = 0; i < 8; i++) {
                    // If possible, build in this direction
                    if (rc.canBuild(dirToBuild, RobotType.SOLDIER)) {
                      rc.build(dirToBuild, RobotType.SOLDIER);
                      built = true;
                      break;
                    } else {
                      // Rotate the direction to try
                      dirToBuild = dirToBuild.rotateLeft();
                    }
                  }
                }
                // if archon has nothing to do, tell soldiers to come to it's location
                /*if (rc.getRoundNum() > 500 && rc.isCoreReady() && rc.isWeaponReady()) {
                	rc.broadcastMessageSignal(-100, 0, 70 * 70);
                }*/
              }
            }
          }
        }
        Clock.yield();
      } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
      }
    }
  }
Example #14
0
  public static void run() throws GameActionException {
    rc = RobotPlayer.rc;
    rand = new Random(rc.getID());

    // build scouts right away
    buildRobot(RobotType.SCOUT);

    while (true) {
      /*
       * INPUT
       */
      if (rc.getLocation().equals(goal)) {
        goal = null; // you made it to the goal
        past10Locations =
            new ArrayList<MapLocation>(); // delete the slug trail after you reach your goal
      }

      // sense locations around you
      nearbyMapLocations =
          MapLocation.getAllMapLocationsWithinRadiusSq(
              rc.getLocation(), rc.getType().sensorRadiusSquared);

      // parts locations
      nearbyPartsLocations = rc.sensePartLocations(RobotType.ARCHON.sensorRadiusSquared);

      // find the nearest mapLocation with the most parts
      double maxParts = 0;
      MapLocation nearbyLocationWithMostParts = null;
      for (MapLocation loc : nearbyPartsLocations) {
        // add to locationsWithParts arraylist
        if (locationsWithParts.contains(loc) == false) {
          locationsWithParts.add(loc);
        }

        // find the location with the most parts
        double partsAtLoc = rc.senseParts(loc);
        if (partsAtLoc > maxParts) {
          maxParts = partsAtLoc;
          nearbyLocationWithMostParts = loc;
        }
      }

      // read signals
      Signal[] signals = rc.emptySignalQueue();
      for (Signal signal : signals) {
        // check if the signal has parts at the location
        int[] message = signal.getMessage();
        if (message != null && message[0] == Utility.PARTS_CODE) {
          // add that location to the locationsWithParts arraylist
          locationsWithParts.add(signal.getLocation());
        }
      }

      // sense robots
      MapLocation myLoc = rc.getLocation();
      robots = rc.senseNearbyRobots();
      foes = new ArrayList<RobotInfo>();
      foesWithinAttackRange = new ArrayList<RobotInfo>();
      for (RobotInfo robot : robots) {
        if (robot.team == Team.ZOMBIE
            || robot.team == rc.getTeam().opponent()) // if the robot is a foe
        {
          foes.add(robot);

          if (myLoc.distanceSquaredTo(robot.location) < robot.type.attackRadiusSquared) {
            foesWithinAttackRange.add(robot);
          }
        }
      }
      int nearbyFoes = foes.size();
      int nearbyFoesInAttackRange = foesWithinAttackRange.size();

      /*//check stats
      double health = rc.getHealth();
      int infectedTurns = rc.getInfectedTurns();
      int robotsAlive = rc.getRobotCount();
      */

      /*
       * OUPUT
       */

      // what to do
      if (nearbyFoes == 0) // if there are no foes in sight
      {
        if (rc.getTeamParts() >= RobotType.TURRET.partCost) // build if you can
        {
          buildRobots();
        } else {
          if (maxParts > 0 && goal == null) // if there are parts nearby
          {
            // make that the goal
            goal = nearbyLocationWithMostParts;
          } else if (goal == null) // if there aren't and there is no goal
          {
            // build something or find new parts
            // 80% build, 20% new parts
            if (locationsWithParts.size() > 0 && rand.nextFloat() > .8) {
              goal = locationsWithParts.get(0);
              locationsWithParts.remove(0);
              goalIsASafeLocation = false;
            }
            // calculate the next goal - maybe a new parts location you got via signal
          } else if (goal != null) // if there is a goal, move there
          {
            moveToLocation(goal);
          }
        }
      } else // there are foes nearby
      {
        // message for help!
        if (Math.random() < probSignal) {
          rc.broadcastSignal(archonInTroubleSignalRadiusSquared);
        }

        if (nearbyFoesInAttackRange > 0) {
          goal = findSaferLocation();
          rc.setIndicatorString(0, "" + goal.x + " " + goal.y);
          goalIsASafeLocation = true;
          moveToLocation(goal);
        }
      }

      Clock.yield();
    }
  }
Example #15
0
  /**
   * run() is the method that is called when a robot is instantiated in the Battlecode world. If
   * this method returns, the robot dies!
   */
  @SuppressWarnings("unused")
  public static void run(RobotController rc) {
    // You can instantiate variables here.
    Direction[] directions = {
      Direction.NORTH,
      Direction.NORTH_EAST,
      Direction.EAST,
      Direction.SOUTH_EAST,
      Direction.SOUTH,
      Direction.SOUTH_WEST,
      Direction.WEST,
      Direction.NORTH_WEST
    };
    RobotType[] robotTypes = {
      RobotType.SCOUT,
      RobotType.SOLDIER,
      RobotType.SOLDIER,
      RobotType.SOLDIER,
      RobotType.GUARD,
      RobotType.GUARD,
      RobotType.VIPER,
      RobotType.TURRET
    };
    Random rand = new Random(rc.getID());
    int myAttackRange = 0;
    Team myTeam = rc.getTeam();
    Team enemyTeam = myTeam.opponent();

    if (rc.getType() == RobotType.ARCHON) {
      try {
        // Any code here gets executed exactly once at the beginning of the game.
      } catch (Exception e) {
        // Throwing an uncaught exception makes the robot die, so we need to catch exceptions.
        // Caught exceptions will result in a bytecode penalty.
        System.out.println(e.getMessage());
        e.printStackTrace();
      }

      while (true) {
        /*
            // This is a loop to prevent the run() method from returning. Because of the Clock.yield()
            // at the end of it, the loop will iterate once per game round.
            try {
                int fate = rand.nextInt(1000);
                // Check if this ARCHON's core is ready
                if (fate % 10 == 2) {
                    // Send a message signal containing the data (6370, 6147)
                    rc.broadcastMessageSignal(6370, 6147, 80);
                }
                Signal[] signals = rc.emptySignalQueue();
                if (signals.length > 0) {
                    // Set an indicator string that can be viewed in the client
                    rc.setIndicatorString(0, "I received a signal this turn!");
                } else {
                    rc.setIndicatorString(0, "I don't any signal buddies");
                }
                if (rc.isCoreReady()) {
                    if (fate < 800) {
                        // Choose a random direction to try to move in
                        Direction dirToMove = directions[fate % 8];
                        // Check the rubble in that direction
                        if (rc.senseRubble(rc.getLocation().add(dirToMove)) >= GameConstants.RUBBLE_OBSTRUCTION_THRESH) {
                            // Too much rubble, so I should clear it
                            rc.clearRubble(dirToMove);
                            // Check if I can move in this direction
                        } else if (rc.canMove(dirToMove)) {
                            // Move
                            rc.move(dirToMove);
                        }
                    } else {
                        // Choose a random unit to build
                        RobotType typeToBuild = robotTypes[fate % 8];
                        // Check for sufficient parts
                        if (rc.hasBuildRequirements(typeToBuild)) {
                            // Choose a random direction to try to build in
                            Direction dirToBuild = directions[rand.nextInt(8)];
                            for (int i = 0; i < 8; i++) {
                                // If possible, build in this direction
                                if (rc.canBuild(dirToBuild, typeToBuild)) {
                                    rc.build(dirToBuild, typeToBuild);
                                    break;
                                } else {
                                    // Rotate the direction to try
                                    dirToBuild = dirToBuild.rotateLeft();
                                }
                            }
                        }
                    }
                }

                Clock.yield();
            } catch (Exception e) {
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        */
      }
    } else if (rc.getType() != RobotType.TURRET) {
      try {
        // Any code here gets executed exactly once at the beginning of the game.
        myAttackRange = rc.getType().attackRadiusSquared;
      } catch (Exception e) {
        // Throwing an uncaught exception makes the robot die, so we need to catch exceptions.
        // Caught exceptions will result in a bytecode penalty.
        System.out.println(e.getMessage());
        e.printStackTrace();
      }

      while (true) {
        // This is a loop to prevent the run() method from returning. Because of the Clock.yield()
        // at the end of it, the loop will iterate once per game round.
        try {
          int fate = rand.nextInt(1000);

          if (fate % 5 == 3) {
            // Send a normal signal
            rc.broadcastSignal(80);
          }

          boolean shouldAttack = false;

          // If this robot type can attack, check for enemies within range and attack one
          if (myAttackRange > 0) {
            RobotInfo[] enemiesWithinRange = rc.senseNearbyRobots(myAttackRange, enemyTeam);
            RobotInfo[] zombiesWithinRange = rc.senseNearbyRobots(myAttackRange, Team.ZOMBIE);
            if (enemiesWithinRange.length > 0) {
              shouldAttack = true;
              // Check if weapon is ready
              if (rc.isWeaponReady()) {
                rc.attackLocation(
                    enemiesWithinRange[rand.nextInt(enemiesWithinRange.length)].location);
              }
            } else if (zombiesWithinRange.length > 0) {
              shouldAttack = true;
              // Check if weapon is ready
              if (rc.isWeaponReady()) {
                rc.attackLocation(
                    zombiesWithinRange[rand.nextInt(zombiesWithinRange.length)].location);
              }
            }
          }

          if (!shouldAttack) {
            if (rc.isCoreReady()) {
              if (fate < 600) {
                // Choose a random direction to try to move in
                Direction dirToMove = directions[fate % 8];
                // Check the rubble in that direction
                if (rc.senseRubble(rc.getLocation().add(dirToMove))
                    >= GameConstants.RUBBLE_OBSTRUCTION_THRESH) {
                  // Too much rubble, so I should clear it
                  rc.clearRubble(dirToMove);
                  // Check if I can move in this direction
                } else if (rc.canMove(dirToMove)) {
                  // Move
                  rc.move(dirToMove);
                }
              }
            }
          }

          Clock.yield();
        } catch (Exception e) {
          System.out.println(e.getMessage());
          e.printStackTrace();
        }
      }
    } else if (rc.getType() == RobotType.TURRET) {
      try {
        myAttackRange = rc.getType().attackRadiusSquared;
      } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
      }

      while (true) {
        // This is a loop to prevent the run() method from returning. Because of the Clock.yield()
        // at the end of it, the loop will iterate once per game round.
        try {
          // If this robot type can attack, check for enemies within range and attack one
          if (rc.isWeaponReady()) {
            RobotInfo[] enemiesWithinRange = rc.senseNearbyRobots(myAttackRange, enemyTeam);
            RobotInfo[] zombiesWithinRange = rc.senseNearbyRobots(myAttackRange, Team.ZOMBIE);
            if (enemiesWithinRange.length > 0) {
              for (RobotInfo enemy : enemiesWithinRange) {
                // Check whether the enemy is in a valid attack range (turrets have a minimum range)
                if (rc.canAttackLocation(enemy.location)) {
                  rc.attackLocation(enemy.location);
                  break;
                }
              }
            } else if (zombiesWithinRange.length > 0) {
              for (RobotInfo zombie : zombiesWithinRange) {
                if (rc.canAttackLocation(zombie.location)) {
                  rc.attackLocation(zombie.location);
                  break;
                }
              }
            }
          }

          Clock.yield();
        } catch (Exception e) {
          System.out.println(e.getMessage());
          e.printStackTrace();
        }
      }
    }
  }
Example #16
0
  public static void run(RobotController rc) {
    int myAttackRange = 0;
    Random rand = new Random(rc.getID());
    Team myTeam = rc.getTeam();
    Team enemyTeam = myTeam.opponent();

    try {
      // Any code here gets executed exactly once at the beginning of the game.
      myAttackRange = rc.getType().attackRadiusSquared;
    } catch (Exception e) {
      // Throwing an uncaught exception makes the robot die, so we need to catch exceptions.
      // Caught exceptions will result in a bytecode penalty.
      System.out.println(e.getMessage());
      e.printStackTrace();
    }

    while (true) {
      // This is a loop to prevent the run() method from returning. Because of the Clock.yield()
      // at the end of it, the loop will iterate once per game round.
      try {
        MapLocation myLoc = rc.getLocation();
        // If this robot type can attack, check for enemies within range and attack one
        // guards only attack ZOMBIES
        RobotInfo[] enemiesWithinRange =
            rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, Team.ZOMBIE);
        RobotInfo[] friendliesWithinRange =
            rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, myTeam);
        int closestArchonDist = 60;
        MapLocation closestArchonLoc = null;
        for (RobotInfo f : friendliesWithinRange) {
          if (f.type == RobotType.ARCHON) {
            MapLocation curArchonLoc = f.location;
            if (myLoc.distanceSquaredTo(curArchonLoc) < closestArchonDist) {
              closestArchonDist = myLoc.distanceSquaredTo(curArchonLoc);
              closestArchonLoc = curArchonLoc;
            }
          }
        }

        if (closestArchonLoc != null) {
          if (enemiesWithinRange.length > 0) {
            RobotInfo nearestEnemyToArchon = enemiesWithinRange[0];
            int nearestEnemyToArchonDist =
                nearestEnemyToArchon.location.distanceSquaredTo(closestArchonLoc);
            for (RobotInfo e : enemiesWithinRange) {
              if (e.location.distanceSquaredTo(closestArchonLoc) < nearestEnemyToArchonDist) {
                nearestEnemyToArchonDist = e.location.distanceSquaredTo(closestArchonLoc);
                nearestEnemyToArchon = e;
              }
            }
            // only attack/move towards if it's within 24 range of the archon
            if (nearestEnemyToArchonDist <= 24) {
              // Check if weapon is ready
              if (rc.isWeaponReady() && rc.canAttackLocation(nearestEnemyToArchon.location)) {
                rc.attackLocation(nearestEnemyToArchon.location);
              } else { // otherwise try to move towards the enemy
                if (rc.isCoreReady()) {
                  // try to move towards enemy
                  Direction dirToMove = myLoc.directionTo(nearestEnemyToArchon.location);
                  if (rc.canMove(dirToMove)) {
                    rc.move(dirToMove);
                  } else if (rc.canMove(dirToMove.rotateLeft())) {
                    rc.move(dirToMove.rotateLeft());
                  } else if (rc.canMove(dirToMove.rotateRight())) {
                    rc.move(dirToMove.rotateRight());
                  }
                }
              }
            }
          } else { // if no enemies, it should try to circle nearest archon
            if (rc.isCoreReady()) {
              Direction dirToMove = myLoc.directionTo(closestArchonLoc);
              if (rc.canMove(dirToMove)) {
                rc.move(dirToMove);
              } else if (rc.canMove(dirToMove.rotateLeft())) {
                rc.move(dirToMove.rotateLeft());
              } else if (rc.canMove(dirToMove.rotateRight())) {
                rc.move(dirToMove.rotateRight());
              }
            }
          }
        } else {
          rc.setIndicatorString(1, "no archon");
          // if no archons nearby, move randomly and attack
          if (enemiesWithinRange.length > 0) {
            RobotInfo nearestEnemy = enemiesWithinRange[0];
            int nearestEnemyDist = nearestEnemy.location.distanceSquaredTo(myLoc);
            for (RobotInfo e : enemiesWithinRange) {
              if (e.location.distanceSquaredTo(myLoc) < nearestEnemyDist) {
                nearestEnemyDist = e.location.distanceSquaredTo(myLoc);
                nearestEnemy = e;
              }
            }
            if (rc.isWeaponReady() && rc.canAttackLocation(nearestEnemy.location)) {
              rc.attackLocation(nearestEnemy.location);
            } else { // otherwise try to move towards the enemy
              if (rc.isCoreReady()) {
                // try to move towards enemy
                Direction dirToMove = myLoc.directionTo(nearestEnemy.location);
                if (rc.canMove(dirToMove)) {
                  rc.move(dirToMove);
                } else if (rc.canMove(dirToMove.rotateLeft())) {
                  rc.move(dirToMove.rotateLeft());
                } else if (rc.canMove(dirToMove.rotateRight())) {
                  rc.move(dirToMove.rotateRight());
                }
              }
            }
          } else if (rc.isCoreReady()) {
            Direction dirToMove = RobotPlayer.directions[(rand.nextInt(8))];
            for (int i = 0; i < 8; i++) {
              if (rc.canMove(dirToMove)) {
                rc.move(dirToMove);
                break;
              } else {
                dirToMove = dirToMove.rotateLeft();
              }
            }
          }
        }
        Clock.yield();
      } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
      }
    }
  }
  public static void run(RobotController rc) {
    sightRadius = RobotType.SOLDIER.sensorRadiusSquared;
    attackRadius = RobotType.SOLDIER.attackRadiusSquared;
    myTeam = rc.getTeam();
    enemyTeam = myTeam.opponent();
    while (true) {
      try {
        numEnemySoldiers = 0;
        totalEnemySoldierHealth = 0;
        myLoc = rc.getLocation();
        nearbyAllies = rc.senseNearbyRobots(sightRadius, myTeam);
        nearbyEnemies = rc.senseHostileRobots(myLoc, sightRadius);
        newArchonLoc = null;

        // clear bad locations
        resetLocations(rc);
        // read messages and get destination
        readMessages(rc);
        // heal if need (and set the archon destination to go to)
        setRetreatingStatus(rc, nearbyEnemies);

        // Remove turret locations that you can see are not there.
        // Does NOT remove turret locations due to broadcasts. Already done in read messages.
        removeTurretLocations(rc);

        if (newArchonLoc != null) {
          nearestArchonLocation = newArchonLoc;
        }

        rc.setIndicatorString(2, "Round: " + rc.getRoundNum() + ", rushing: " + rush);
        // Reset rushing if turns since rush is > 20 and see no more enemies.
        if (rush && myLoc.distanceSquaredTo(rushLocation) <= 100) turnsSinceRush++;
        if (turnsSinceRush > 20) {
          if (rc.senseNearbyRobots(sightRadius, enemyTeam).length == 0) {
            turnsSinceRush = 0;
            rush = false;
          }
        }

        // When rushing, be mad aggressive.
        if (rush) {
          rushMicro(rc, nearbyEnemies);
        }
        // When retreating, retreat
        else if (healing) {
          if (rc.isCoreReady()) {
            if (nearestArchonLocation != null) {
              if (myLoc.distanceSquaredTo(nearestArchonLocation) > 13) {
                bugging.enemyAvoidMove(nearbyEnemies);
                // Get away from archons that are not too close together.
              } else if (myLoc.distanceSquaredTo(nearestArchonLocation) <= 2) {
                Direction radialDir = nearestArchonLocation.directionTo(myLoc);
                Direction awayDir = Movement.getBestMoveableDirection(radialDir, rc, 2);
                if (awayDir != Direction.NONE) {
                  rc.move(awayDir);
                }
              }
            }
          }
          // Make sure to attack people even when retreating.
          // Prioritize the closest enemy. Then the closest zombie.
          if (rc.isWeaponReady()) {
            // Attack the closest enemy. If there is not one, then attack the closest zombie
            int closestDist = 10000;
            RobotInfo target = null;
            for (RobotInfo hostile : nearbyEnemies) {
              int dist = myLoc.distanceSquaredTo(hostile.location);
              if (rc.canAttackLocation(hostile.location)) {
                // There is already is a target
                if (target != null) {
                  if (target.team == enemyTeam) {
                    // Target is already enemy, so prioritize the closest
                    if (hostile.team == enemyTeam) {
                      if (dist < closestDist) {
                        target = hostile;
                        closestDist = dist;
                      }
                    } // If hostile is not an enemy, not worth considering.
                  } else {
                    // Target is not on enemy team, so hostile is best choice!
                    if (hostile.team == enemyTeam) {
                      target = hostile;
                      closestDist = dist;
                      // Both are zombies, so just pick the closest.
                    } else {
                      if (dist < closestDist) {
                        target = hostile;
                        closestDist = dist;
                      }
                    }
                  }
                  // Set a target when there is not one.
                } else {
                  target = hostile;
                  closestDist = dist;
                }
              }
            }
            // We know that if there is a target, we can attack it.
            if (target != null) {
              rc.attackLocation(target.location);
            }
          }
        }

        // When viper infected and will die from the infection, do special micro
        else if (isViperInfected(rc)
            && (rc.getHealth() < rc.getViperInfectedTurns() * 2 || rc.getRoundNum() > 2100)) {
          viperInfectedMicro(rc);
        }

        // if there are enemies in range, we should focus on attack and micro
        else if (nearbyEnemies.length > 0) {
          if (shouldLure(rc, nearbyEnemies, nearbyAllies)) luringMicro(rc);
          else micro(rc);
        } else { // otherwise, we should always be moving somewhere
          moveSoldier(rc);
        }

        Clock.yield();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Example #18
0
  public static void run(RobotController rc) {
    int myAttackRange = 0;
    Random rand = new Random(rc.getID());
    Team myTeam = rc.getTeam();
    Team enemyTeam = myTeam.opponent();

    try {
      // Any code here gets executed exactly once at the beginning of the game.
      myAttackRange = rc.getType().attackRadiusSquared;
    } catch (Exception e) {
      // Throwing an uncaught exception makes the robot die, so we need to catch exceptions.
      // Caught exceptions will result in a bytecode penalty.
      System.out.println(e.getMessage());
      e.printStackTrace();
    }

    while (true) {
      // This is a loop to prevent the run() method from returning. Because of the Clock.yield()
      // at the end of it, the loop will iterate once per game round.
      try {
        int fate = rand.nextInt(1000);

        if (fate % 5 == 3) {
          // Send a normal signal
          rc.broadcastSignal(80);
        }

        boolean shouldAttack = false;

        // If this robot type can attack, check for enemies within range and attack one
        if (myAttackRange > 0) {
          RobotInfo[] enemiesWithinRange = rc.senseNearbyRobots(myAttackRange, enemyTeam);
          RobotInfo[] zombiesWithinRange = rc.senseNearbyRobots(myAttackRange, Team.ZOMBIE);
          if (enemiesWithinRange.length > 0) {
            shouldAttack = true;
            // Check if weapon is ready
            if (rc.isWeaponReady()) {
              rc.attackLocation(
                  enemiesWithinRange[rand.nextInt(enemiesWithinRange.length)].location);
            }
          } else if (zombiesWithinRange.length > 0) {
            shouldAttack = true;
            // Check if weapon is ready
            if (rc.isWeaponReady()) {
              rc.attackLocation(
                  zombiesWithinRange[rand.nextInt(zombiesWithinRange.length)].location);
            }
          }
        }

        if (!shouldAttack) {
          if (rc.isCoreReady()) {
            if (fate < 600) {
              // Choose a random direction to try to move in
              Direction dirToMove = RobotPlayer.directions[fate % 8];
              // Check the rubble in that direction
              if (rc.senseRubble(rc.getLocation().add(dirToMove))
                  >= GameConstants.RUBBLE_OBSTRUCTION_THRESH) {
                // Too much rubble, so I should clear it
                rc.clearRubble(dirToMove);
                // Check if I can move in this direction
              } else if (rc.canMove(dirToMove)) {
                // Move
                rc.move(dirToMove);
              }
            }
          }
        }

        Clock.yield();
      } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
      }
    }
  }
Example #19
0
  /**
   * @Nathan - Should we adjust these priorities (specifically where should building troops be?)
   * TODO for archons - 1) repair nearest injured unit 2) signal turtle location 3) pick up adjacent
   * parts and activate neutral units 4) move to turtle corner 5) build troops 6) run away from
   * enemies
   *
   * @param rc
   * @throws GameActionException
   */
  private static void archon(RobotController rc) {
    numArchons = rc.getInitialArchonLocations(myTeam).length;
    turtleCorner = LOCATION_NONE;
    while (true) {
      try {
        // 1) repair nearest injured unit
        repairFirst(rc);
        // 2) signal turtle location - every 25 turns
        int broadcastRadius = rc.getType().sensorRadiusSquared * (2 + (rc.getRobotCount() / 50));
        if (rc.getRoundNum() > 100 && rc.getRoundNum() % 30 == 0 && turtleCorner != LOCATION_NONE) {
          rc.broadcastMessageSignal(turtleCorner.x, turtleCorner.y, broadcastRadius);
        }

        // @Nathan - Intro mode is all you -- I just pasted all the text into a separate method for
        // clarity
        if (turtleCorner != LOCATION_NONE && currentMode != TURTLE_MODE) {
          currentMode = TRANSITION_MODE;
        }
        if (currentMode == INTRO_MODE) {
          archonIntroMode(rc);
          // if (turtleCorner.equals(LOCATION_NONE)) tryToLocateCorner(rc);
        }
        // 4) Move to turtle corner
        if (currentMode == TRANSITION_MODE) {
          if (rc.getLocation().distanceSquaredTo(turtleCorner) > 4) {
            moveTowards(rc, rc.getLocation().directionTo(turtleCorner));
          } else {
            // TODO get in proper position
            currentMode = TURTLE_MODE;
            rc.broadcastMessageSignal(SENDING_MODE, TURTLE_MODE, rc.getType().sensorRadiusSquared);
          }
        }

        // 5) Build Troops !
        // @Nathan do we need to build more scouts in turtle mode so we can do more kiting?
        boolean hasNearbyEnemies = isNearbyEnemies(rc);
        if (!hasNearbyEnemies && rc.getRobotCount() - numArchons < NUM_INTRO_SCOUTS) {
          tryToBuild(rc, RobotType.SCOUT);
          Direction directionToTargetCorner = calculateDirectionToClosestCorner(rc);
          rc.broadcastMessageSignal(
              SENDING_TARGET_DIRECTION, DIRECTION_TO_SIGNAL.get(directionToTargetCorner), 4);
        }
        if ((rc.getRobotCount() <= 30 || hasNearbyEnemies)) {
          tryToBuild(rc, RobotType.SOLDIER);
        }
        if (rc.getRobotCount() > 30 && !hasNearbyEnemies) {
          tryToBuild(rc, RobotType.TURRET);
        }
        // 6) if senses enemy troop that is not a scout, run away from it
        if (hasNearbyEnemies) moveAwayFromEnemies(rc);
        // 3) Pick up parts on current square, check for adjacent parts and try to collect them
        collectParts(rc);
        // 3a) activate any nearby units
        activateUnits(rc);
        rc.setIndicatorString(0, "Turtle x: " + turtleCorner.x + "Turtle y: " + turtleCorner.y);
        rc.setIndicatorString(1, "Current Mode" + currentMode);
        Clock.yield(); // end turn
      } catch (GameActionException e) {
        e.printStackTrace();
      }
    }
  }
Example #20
0
  public static void run(RobotController rc) {
    team = rc.getTeam();
    while (true) {
      try {
        myLoc = rc.getLocation();
        int numOurTurrets = 0;

        // Move opposite of ally scout. Also keep track of our number of turrets.
        // Try to pair with ally turret.
        RobotInfo[] allies = rc.senseNearbyRobots(myLoc, sightRange, team);
        isPaired = false;
        int followedTurretDist = 10000;
        for (RobotInfo ally : allies) {
          if (ally.type == RobotType.SCOUT) {
            int randInt = rand.nextInt(3);
            if (randInt == 0) {
              mainDir = ally.location.directionTo(myLoc);
            } else if (randInt == 1) {
              mainDir = ally.location.directionTo(myLoc).rotateLeft();
            } else {
              mainDir = ally.location.directionTo(myLoc).rotateRight();
            }
          } else if (ally.type == RobotType.TURRET || ally.type == RobotType.TTM) {
            numOurTurrets++;
            int dist = myLoc.distanceSquaredTo(ally.location);
            if (dist < followedTurretDist) {
              // Try to pair with this turret.
              // Confirm that no other scout allies are nearby.
              RobotInfo[] otherAllies = rc.senseNearbyRobots(ally.location, dist, team);
              boolean canPairWith = true;
              for (RobotInfo otherAlly : otherAllies) {
                if (otherAlly.type == RobotType.SCOUT) {
                  int otherDist = ally.location.distanceSquaredTo(otherAlly.location);
                  if (otherDist < dist) {
                    canPairWith = false;
                    break;
                  }
                }
              }
              if (canPairWith) {
                // This is turret we can pair with.
                isPaired = true;
                followedTurretDist = dist;
                pairedTurret = ally.location;
              }
            }
          }
        }
        rc.setIndicatorString(0, "Round: " + rc.getRoundNum() + ", Is paired: " + isPaired);

        int numEnemyTurrets = 0;
        boolean inEnemyAttackRangeAndPaired = false;
        Direction dodgeEnemyDir = Direction.NONE;
        boolean inDanger = false;

        RobotInfo[] hostiles = rc.senseHostileRobots(myLoc, sightRange);
        if (isPaired) {
          if (hostiles.length > 0) {
            closestTurretLoc = null;
            int closestDist = 10000;
            RobotInfo closestEnemy = hostiles[0];
            RobotInfo bestEnemy = hostiles[0];
            // Find the best enemy.
            // In the meantime, also find the closest enemy that can hit me and get away.
            MapLocation enemyTurretLoc = null;
            MapLocation enemyScoutLoc = null;
            for (RobotInfo hostile : hostiles) {
              int dist = myLoc.distanceSquaredTo(hostile.location);
              if (hostile.type == RobotType.SCOUT) {
                enemyScoutLoc = hostile.location;
              } else if (hostile.type == RobotType.TURRET) {
                enemyTurretLoc = hostile.location;
              } else if (hostile.type == RobotType.ZOMBIEDEN) {
                // if (rc.isCoreReady()) {
                if (!hostile.location.equals(previouslyBroadcastedDen)) {
                  if (myLoc.distanceSquaredTo(pairedTurret) <= 2) {
                    previouslyBroadcastedDen = hostile.location;
                    Message.sendMessageGivenDelay(rc, hostile.location, Message.ZOMBIEDEN, 10);
                  }
                }
                // }
              }

              // First handle finding the best enemy.
              // make sure hostile range is > 5
              if (hostile.location.distanceSquaredTo(pairedTurret)
                      <= RobotType.TURRET.attackRadiusSquared
                  && hostile.location.distanceSquaredTo(pairedTurret) > 5) {
                if (bestEnemy.type == RobotType.ARCHON) {
                  if (hostile.type == RobotType.ARCHON) {
                    if (hostile.health < bestEnemy.health) {
                      bestEnemy = hostile;
                    }
                  }
                } else {
                  if (hostile.type == RobotType.ARCHON) {
                    bestEnemy = hostile;
                  } else {
                    if (hostile.health < bestEnemy.health) {
                      bestEnemy = hostile;
                    }
                  }
                }
              }
              // Then find the closest turret
              if (closestTurretDist > dist
                  && hostile.type == RobotType.TURRET
                  && hostile.location.distanceSquaredTo(pairedTurret) > 5) {
                closestTurretDist = dist;
                closestTurretLoc = hostile.location;
              }

              // Find the closest enemy
              if (closestDist > dist
                  && hostile.type != RobotType.ARCHON
                  && hostile.location.distanceSquaredTo(pairedTurret) > 5) {
                closestDist = dist;
                closestEnemy = hostile;
              }

              // If my closest enemy can hit me, get away.
              if (closestEnemy.location.distanceSquaredTo(myLoc)
                  <= closestEnemy.type.attackRadiusSquared) {
                inEnemyAttackRangeAndPaired = true;
                // Find a direction closest to paired turret that is not in attack range.
                int closestPairedDist = 10000;
                for (Direction dir : RobotPlayer.directions) {
                  if (rc.canMove(dir)) {
                    MapLocation dirLoc = myLoc.add(dir);
                    int pairedDist = dirLoc.distanceSquaredTo(pairedTurret);
                    if (dirLoc.distanceSquaredTo(closestEnemy.location)
                        > closestEnemy.type.attackRadiusSquared) {
                      if (closestPairedDist > pairedDist) {
                        closestPairedDist = pairedDist;
                        dodgeEnemyDir = dir;
                      }
                    }
                  }
                }
              }
            }
            // If there is a best enemy, send a message.
            if (bestEnemy != null
                && bestEnemy.location.distanceSquaredTo(pairedTurret) > 5
                && rc.isCoreReady()) {
              Message.sendMessageGivenRange(rc, bestEnemy.location, Message.PAIREDATTACK, 15);
            }

            // If there is a closest turret, send a message.
            if (closestTurretLoc != null && rc.isCoreReady()) {
              Message.sendMessageGivenDelay(rc, closestTurretLoc, Message.TURRET, 2.25);
              previouslyBroadcastedClosestTurretLoc = closestTurretLoc;
            }

            if (previouslyBroadcastedClosestTurretLoc != null
                && closestTurretLoc == null
                && rc.isCoreReady()) {
              Message.sendMessageGivenDelay(
                  rc, previouslyBroadcastedClosestTurretLoc, Message.TURRETKILLED, 2.25);
            }

            // if it sees enemy turret with a scout, signal that
            if (enemyScoutLoc != null && enemyTurretLoc != null && rc.isCoreReady()) {
              Message.sendMessageGivenRange(rc, enemyTurretLoc, Message.ENEMYTURRETSCOUT, 8);
            }
          }

        } else {
          // If sees an enemy, get away and record the two closest enemies. Then broadcast the
          // location while running away.
          // If Scout sees Den, then just broadcast immediately.
          // If Scout sees other enemies, then wait until far enough to broadcast.
          closestRecordedEnemy = null; // does not include the Den!
          secondClosestRecordedEnemy = null; // does not include the Den!
          int closestRecordedEnemyDist = 10000;
          int secondClosestRecordedEnemyDist = 20000;
          if (hostiles.length > 0) {
            MapLocation realLoc = myLoc.add(mainDir);
            int closestAttackingEnemyDist = 10000;
            for (RobotInfo hostile : hostiles) {
              if (hostile.type == RobotType.ZOMBIEDEN) {
                if (!hostile.location.equals(previouslyBroadcastedDen)) {
                  previouslyBroadcastedDen = hostile.location;
                  // if (rc.isCoreReady()) {
                  Message.sendMessageGivenDelay(rc, hostile.location, Message.ZOMBIEDEN, 10);
                  Direction dir = hostile.location.directionTo(myLoc);
                  if (rc.canMove(dir)) {
                    mainDir = dir;
                  } else if (rc.canMove(dir.rotateLeft())) {
                    mainDir = dir.rotateLeft();
                  } else if (rc.canMove(dir.rotateRight())) {
                    mainDir = dir.rotateRight();
                  }
                  // }
                }
              } else {
                if (hostile.type == RobotType.TURRET) {
                  numEnemyTurrets++;
                }
                // In danger only if someone can attack me.
                if (hostile.type != RobotType.ARCHON) {
                  int dist = realLoc.distanceSquaredTo(hostile.location);
                  if (hostile.type == RobotType.ZOMBIEDEN) {
                    if (dist <= 5) {
                      inDanger = true;
                    }
                  } else if (hostile.type == RobotType.TURRET) {
                    if (dist <= hostile.type.attackRadiusSquared) inDanger = true;
                  } else {
                    if (dist <= hostile.type.sensorRadiusSquared) inDanger = true;
                  }
                }

                int dist = myLoc.distanceSquaredTo(hostile.location);
                if (closestRecordedEnemy == null) {
                  closestRecordedEnemy = hostile;
                } else if (dist
                    < closestRecordedEnemyDist) { // update the two closest stored locations.
                  secondClosestRecordedEnemyDist = closestRecordedEnemyDist;
                  secondClosestRecordedEnemy = closestRecordedEnemy;
                  closestRecordedEnemyDist = dist;
                  closestRecordedEnemy = hostile;
                } else if (dist
                    < secondClosestRecordedEnemyDist) { // update the second closest stored location
                                                        // only.
                  secondClosestRecordedEnemyDist = dist;
                  secondClosestRecordedEnemy = hostile;
                }
              }
            }
            if (rc.isCoreReady()) {
              if (closestRecordedEnemy != null) {
                if (closestRecordedEnemyDist <= closestRecordedEnemy.type.attackRadiusSquared) {
                  // Send a message of the closest enemy
                  broadcastRecordedEnemy(rc, closestRecordedEnemy);
                  if (secondClosestRecordedEnemy != null) {
                    // Send a message of the second closest enemy.
                    broadcastRecordedEnemy(rc, secondClosestRecordedEnemy);
                  }
                }
              }
            }
          }
        }

        // Broadcast collectibles
        if (rc.isCoreReady()) {
          if (numTurnsStationary < 10) {
            if (isPaired) {
              if (myLoc.distanceSquaredTo(pairedTurret) <= 2) {
                broadcastCollectibles(rc, hostiles.length > 0);
              }
            } else {
              broadcastCollectibles(rc, hostiles.length > 0);
            }
          }
        }

        // Every 50 turns, broadcast whether or not I am paired
        if (rc.getRoundNum() % 50 == 0) {
          int messageType = isPaired ? Message.PAIRED : Message.UNPAIRED;
          if (isPaired) {
            if (myLoc.distanceSquaredTo(pairedTurret) <= 2) {
              if (hostiles.length > 0) {
                Message.sendMessageGivenDelay(rc, myLoc, messageType, 8);
              } else {
                Message.sendMessageGivenDelay(rc, myLoc, messageType, 0.3);
              }
            }
          } else {
            if (hostiles.length > 0) {
              Message.sendMessageGivenDelay(rc, myLoc, messageType, 8);
            } else {
              Message.sendMessageGivenDelay(rc, myLoc, messageType, 0.3);
            }
          }
        }

        // When we have more turrets, broadcast that.
        if (numOurTurrets > numEnemyTurrets && isPaired && rc.isCoreReady()) {
          if (myLoc.distanceSquaredTo(pairedTurret) <= 2) {
            if (closestTurretLoc != null) {
              Message.sendMessageGivenRange(rc, closestTurretLoc, Message.RUSH, 2 * sightRange);
            } else {
              Message.sendMessageGivenRange(
                  rc, new MapLocation(0, 0), Message.RUSHNOTURRET, 2 * sightRange);
            }
          }
        }

        // When paired, move along with the turret
        // Otherwise move in your main direction, and change it accordingly if you cannot move.
        if (isPaired) {
          if (rc.isCoreReady()) {
            if (inEnemyAttackRangeAndPaired) {
              // mainDir already computed above.
              if (dodgeEnemyDir != Direction.NONE) {
                mainDir = dodgeEnemyDir;
                rc.move(mainDir);
                numTurnsStationary = 0;
              }
            } else {
              // When not in enemy attack range, cling to paired turret (and make sure not to get
              // hit!)
              Direction dirToTurret = myLoc.directionTo(pairedTurret);
              // If right next to turret, then circle around turret
              if (myLoc.add(dirToTurret).equals(pairedTurret)) {
                Direction left = dirToTurret.rotateLeft();
                if (rc.canMove(left) && !inEnemyAttackRange(myLoc.add(left), hostiles)) {
                  mainDir = left;
                  rc.move(mainDir);
                  numTurnsStationary = 0;
                } else {
                  Direction right = dirToTurret.rotateRight();
                  if (rc.canMove(right) && !inEnemyAttackRange(myLoc.add(right), hostiles)) {
                    mainDir = right;
                    rc.move(mainDir);
                    numTurnsStationary = 0;
                  }
                }
              }
              // Otherwise, move closer to the turret.
              else {
                Direction closerDir = Movement.getBestMoveableDirection(dirToTurret, rc, 2);
                if (closerDir != Direction.NONE
                    && !inEnemyAttackRange(myLoc.add(closerDir), hostiles)) {
                  mainDir = closerDir;
                  rc.move(mainDir);
                  numTurnsStationary = 0;
                }
              }
            }
          }
        } else {
          rc.setIndicatorString(1, "Round: " + rc.getRoundNum() + ", In Danger: " + inDanger);
          if (rc.isCoreReady()) {
            if (inDanger) {
              // Go in direction maximizing the minimum distance
              int maxMinDist = 0;
              for (Direction dir : RobotPlayer.directions) {
                if (rc.canMove(dir)) {
                  MapLocation dirLoc = myLoc.add(dir);
                  int minDist = 10000;
                  for (RobotInfo hostile : hostiles) {
                    int dist = dirLoc.distanceSquaredTo(hostile.location);
                    minDist = Math.min(dist, minDist);
                  }
                  if (maxMinDist < minDist) {
                    maxMinDist = minDist;
                    mainDir = dir;
                  }
                }
              }
              rc.setIndicatorString(
                  2,
                  "Round: "
                      + rc.getRoundNum()
                      + ", Max min dist: "
                      + maxMinDist
                      + ", Dir: "
                      + mainDir);
              if (rc.canMove(mainDir)) {
                rc.move(mainDir);
                numTurnsStationary = 0;
              }
            } else {
              if (!rc.canMove(mainDir)) {
                int[] disps = {1, -1, 3, -3};
                for (int disp : disps) {
                  Direction dir = RobotPlayer.directions[((mainDir.ordinal() + disp) % 8 + 8) % 8];
                  if (rc.canMove(dir)) {
                    mainDir = dir;
                    break;
                  }
                }
              }
              if (rc.canMove(mainDir)) {
                rc.move(mainDir);
                numTurnsStationary = 0;
              }
            }
          }
        }
        numTurnsStationary++;
        Clock.yield();
      } catch (Exception e) {
        e.printStackTrace();
        Clock.yield();
      }
    }
  }
Example #21
0
  private static void scout(RobotController rc) {
    // do one time things here
    Direction targetDirection = Direction.NONE;
    while (true) {
      try {
        // TODO - I've made it so the scouts will go in pairs now; not sure if we want this later or
        // not, but they
        // aren't avoiding enemies well enough
        if (currentMode == INTRO_MODE && rc.getRoundNum() >= 40) {
          // TODO - scouts don't pick their directions well enough - try running diffusion.
          // one often starts already in/near a corner; if we find a corner very close, we should
          // probably just move to it
          // and turtle right away (even if we don't know about the others yet)
          if (targetDirection.equals(Direction.NONE)) {
            targetDirection = getScoutTargetDirection(rc);
          }

          //					RobotInfo[] zombies = rc.senseNearbyRobots(-1, Team.ZOMBIE);
          // TODO: bring this back in, but only if there aren't bots that will attack the scout
          // (otherwise, the delay makes them too vulnerable; finding corners matters more first)
          //					for (RobotInfo zombie : zombies) {
          //						if (zombie.type == RobotType.ZOMBIEDEN) {
          //							if (!ZOMBIE_DEN_LOCATIONS.contains(zombie.location)) {
          //								ZOMBIE_DEN_LOCATIONS.add(zombie.location);
          //								rc.broadcastMessageSignal(SENDING_DEN_X, zombie.location.x, fullMapRadius);
          //								rc.broadcastMessageSignal(SENDING_DEN_Y, zombie.location.y, fullMapRadius);
          //							}
          //						}
          //					}
          //					int start = Clock.getBytecodeNum();
          MapLocation corner = checkForCorner(rc, targetDirection);
          //					System.out.println("CheckforCorner: " + (Clock.getBytecodeNum() - start));
          if (!corner.equals(LOCATION_NONE)) {
            rc.broadcastMessageSignal(SENDING_CORNER_X, corner.x, fullMapRadius);
            rc.broadcastMessageSignal(SENDING_CORNER_Y, corner.y, fullMapRadius);
            // head to opposite in case other scout didn't make it
            // TODO or scout around for other zombie dens, kite, etc.
            targetDirection = targetDirection.opposite();
          }
          //					start = Clock.getBytecodeNum();
          moveCautiously(rc, targetDirection);
          //					System.out.println("moveCautiously: " + (Clock.getBytecodeNum() - start));
        } else { // not intro mode; do kiting
          RobotInfo[] zombies = rc.senseNearbyRobots(-1, Team.ZOMBIE);
          if (zombies.length > 0) {
            turnsToCheckForZombies = NUM_TURNS_TO_CHECK_FOR_ZOMBIES;
          }
          if (turnsToCheckForZombies > 0) {
            turnsToCheckForZombies--;
            leadZombiesToEnemy(rc);
          } else {

          }
          //				rc.sensePartLocations(-1); //TODO
        }
        Clock.yield();
      } catch (GameActionException e) {
        e.printStackTrace();
      }
    }
  }