/** * 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(); } }
// In this function the HQ spawns a soldier ideally toward the enemy base but in any direction // otherwise public static void SpawnSoldiers(RobotController rc) { try { if (rc.isActive() && rc.getType() == RobotType.HQ) { Direction toEnemy = rc.getLocation().directionTo(rc.senseEnemyHQLocation()); if (rc.senseObjectAtLocation(rc.getLocation().add(toEnemy)) == null) { } else { for (int i = 0; i < 7; i++) { toEnemy = toEnemy.rotateLeft(); if (rc.senseObjectAtLocation(rc.getLocation().add(toEnemy)) == null) { i = 47; } else if (i == 6) { toEnemy = Direction.NONE; } } } if (toEnemy != Direction.NONE) { if (rc.isActive()) { if (rc.getType() == RobotType.HQ) { rc.spawn(toEnemy); } } } } } catch (Exception e) { e.printStackTrace(); System.out.println("Utility Exception"); } }
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(); } }
private static void archonIntroMode(RobotController rc) throws GameActionException { processIntroMessageSignals(rc); // TODO: what if, after an appropriate number of turns, the scouts haven't reported anything? // should we have all of the archons move together in some direction and hope it is towards a // corner? if (SCOUTED_CORNERS.size() >= 2 && turtleCorner.equals(LOCATION_NONE)) { List<Direction> crossDirections = Arrays.asList( Direction.NORTH_WEST, Direction.NORTH_EAST, Direction.SOUTH_WEST, Direction.SOUTH_EAST); if (!(crossDirections.contains(SCOUTED_CORNERS.get(0).directionTo(SCOUTED_CORNERS.get(1))) || SCOUTED_CORNERS.size() > 2)) { // TODO if they are not opposite, make a scout and send to one of the remaining corners } else { MapLocation[] newCorners = { new MapLocation(SCOUTED_CORNERS.get(0).x, SCOUTED_CORNERS.get(1).y), new MapLocation(SCOUTED_CORNERS.get(1).x, SCOUTED_CORNERS.get(0).y) }; for (MapLocation corner : newCorners) { if (!SCOUTED_CORNERS.contains(corner)) { SCOUTED_CORNERS.add(corner); } } currentMode = TRANSITION_MODE; turtleCorner = findBestTurtleCorner(rc); for (MapLocation corner : SCOUTED_CORNERS) { if (crossDirections.contains(turtleCorner.directionTo(corner))) { fullMapRadius = turtleCorner.distanceSquaredTo(corner); break; } } // TODO (also broadcast this locally to scouts when you make them? So they can message // back more efficiently, if they have to) rc.broadcastMessageSignal( SENDING_MODE, TRANSITION_MODE, rc.getType().sensorRadiusSquared * 2); rc.broadcastMessageSignal( SENDING_TURTLE_X, turtleCorner.x, rc.getType().sensorRadiusSquared * 2); rc.broadcastMessageSignal( SENDING_TURTLE_Y, turtleCorner.y, rc.getType().sensorRadiusSquared * 2); } } if (!turtleCorner.equals(LOCATION_NONE)) { currentMode = TRANSITION_MODE; } // TODO gathering parts (need locations from scouts first...) if (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 finds a zombie den, it signals out to surrounding robots If rc has no weapon delay, * attacks in the following priority: 1) adjacent robots (if robot is a bigzombie or standard * zombie move away every other turn to kite it) 2) big zombies 3) nearest enemy * * @param rc RobotController which will attack * @param RobotController * @throws GameActionException * @return true if this robot attacked else false */ private static void attackFirst(RobotController rc) throws GameActionException { boolean equalHealth = true; int lowestHealthIndex = -1; int lowestDistanceIndex = -1; int attackIndex = -1; RobotInfo[] enemies = rc.senseHostileRobots(rc.getLocation(), rc.getType().attackRadiusSquared); if (rc.isWeaponReady() && enemies.length > 0) { for (int i = 0; i < enemies.length; i++) { if (enemies[i].type == RobotType.ZOMBIEDEN) { rc.broadcastSignal(rc.getType().sensorRadiusSquared * 2); } if (attackIndex < 0 && (rc.getLocation()).isAdjacentTo(enemies[i].location)) { attackIndex = i; // TODO test this part - work on kiting if ((enemies[i].type == RobotType.BIGZOMBIE || enemies[i].type == RobotType.STANDARDZOMBIE) && rc.getRoundNum() % 2 == 0 && rc.isCoreReady()) { moveAwayFromEnemy(rc, rc.getLocation().directionTo(enemies[i].location)); } if (rc.isWeaponReady()) { rc.attackLocation(enemies[i].location); } } if (rc.isWeaponReady() && enemies[i].type == RobotType.BIGZOMBIE) { attackIndex = i; rc.attackLocation(enemies[i].location); } if (attackIndex < 0) { lowestHealthIndex = lowestHealthIndex < 0 ? 0 : lowestHealthIndex; lowestDistanceIndex = lowestDistanceIndex < 0 ? 0 : lowestDistanceIndex; equalHealth = equalHealth && enemies[i].health == enemies[lowestHealthIndex].health; lowestDistanceIndex = rc.getLocation().distanceSquaredTo(enemies[i].location) < rc.getLocation().distanceSquaredTo(enemies[lowestDistanceIndex].location) ? i : lowestDistanceIndex; lowestHealthIndex = enemies[i].health < enemies[lowestHealthIndex].health ? i : lowestHealthIndex; } } if (attackIndex < 0 && enemies.length > 0) { attackIndex = equalHealth ? lowestDistanceIndex : lowestHealthIndex; } if (attackIndex >= 0 && rc.isWeaponReady()) { rc.attackLocation(enemies[attackIndex].location); } } }
public static void run(RobotController myRC) { BaseRobot br = null; try { switch (myRC.getType()) { case HQ: br = new HQRobot(myRC); break; case SOLDIER: br = new SoldierRobot(myRC); break; case ARTILLERY: br = new Artillery(myRC); break; default: br = new PassiveEncampment(myRC); } while (true) { br.curRound = Clock.getRoundNum(); br.run(); br.rc.yield(); } } catch (Exception e) { // DEBUG System.out.println("Shit happened!"); e.printStackTrace(); br.rc.addMatchObservation(e.toString()); } }
public static void HqCommand() throws GameActionException { if (rc.getType() == RobotType.HQ) { // if (rc.isActive()) { // Spawn a soldier int[] directionOffSets = {0, 1, -1, 2, -2}; // Team mineSpawn = rc.senseMine(rc.getLocation().add(spawnDir)); Direction dir = rc.getLocation().directionTo(rc.senseEnemyHQLocation()); // this does not work! Direction spawnDir = dir; // spawn robots in the direction of the enemy if (rc.senseMine(rc.getLocation().add(dir)) != null) { lookForDir: for (int d : directionOffSets) { spawnDir = Direction.values()[(dir.ordinal() + d + 8) % 8]; if (rc.canMove(spawnDir) && rc.senseMine(rc.getLocation().add(spawnDir)) != null) { rc.spawn(Direction.SOUTH); rc.spawn(spawnDir); break lookForDir; } } } if (rc.canMove(dir)) { rc.spawn(dir); } // } } }
public static void run(RobotController theRC) { rc = theRC; // These don't change so get them once and use the local variable (performance) myType = rc.getType(); myTeam = rc.getTeam(); enemyTeam = myTeam.opponent(); myHQ = rc.senseHQLocation(); myLoc = rc.getLocation(); senseRange = myType.sensorRadiusSquared; attackRange = myType.attackRadiusSquared; maxRounds = rc.getRoundLimit(); if (myType == RobotType.MISSILE) runMissile(); if (myType.canMove()) { bfs = new Bfs(rc); // We need to check the breadth first search results to move optimally } threats = new Threats(rc); if (myType == RobotType.HQ) runHQ(); else if (myType == RobotType.TOWER) runTower(); else if (myType.isBuilding) runBuilding(); else if (myType.canBuild()) runBeaver(); else if (myType.canMine()) runMiner(); // Includes Beavers else if (myType == RobotType.DRONE) runDrone(); else if (myType.canAttack() || myType == RobotType.LAUNCHER) runCombat(); else runOther(); }
// TODO this method needs a lot of work...isn't doing things properly even if there's just an // archon making bots with open space around it. Add onto that later, when there are more bots // around, // others will need to move forward in order for those just next to the archon to move. private static void moveAwayFromArchons(RobotController rc) throws GameActionException { int mySenseRadius = rc.getType().sensorRadiusSquared; int archonReserveDistance = 9; // @Hope make this more finessed archonReserveDistance = archonReserveDistance < mySenseRadius ? archonReserveDistance : mySenseRadius; List<RobotInfo> robots = Arrays.asList(rc.senseNearbyRobots(archonReserveDistance, myTeam)); List<RobotInfo> archons = new ArrayList<>(); for (RobotInfo robot : robots) { if (robot.type == RobotType.ARCHON) { archons.add(robot); } } boolean tooClose = false; MapLocation myLocation = rc.getLocation(); for (RobotInfo archon : archons) { if (!tooClose && myLocation.distanceSquaredTo(archon.location) < archonReserveDistance) { tooClose = true; } } if (tooClose) { for (RobotInfo archon : archons) { if (rc.isCoreReady()) moveTowards(rc, rc.getLocation().directionTo(archon.location).opposite()); } } }
public static void run(RobotController _rc) throws Exception { switch (_rc.getType()) { case ARCHON: Archon.run(_rc); break; case GUARD: Guard.run(_rc); break; case SCOUT: Scout.run(_rc); break; case SOLDIER: Soldier.run(_rc); break; case TTM: case TURRET: Turret.run(_rc); break; case VIPER: Viper.run(_rc); break; default: // this shouldn't happen throw new Exception("I am a bad robot."); } }
public void run() { while (true) { if (rc.getType() == RobotType.SOLDIER) { switch (corner) { case 1: Utilities.MoveMapLocation(rc, new MapLocation(2, 2), true); break; case 2: Utilities.MoveMapLocation(rc, new MapLocation(rc.getMapWidth() - 3, 2), true); break; case 3: Utilities.MoveMapLocation(rc, new MapLocation(2, rc.getMapHeight() - 3), true); break; default: Utilities.MoveMapLocation( rc, new MapLocation(rc.getMapWidth() - 3, rc.getMapHeight() - 3), true); break; } if (rc.isActive()) { try { rc.construct(RobotType.PASTR); } catch (Exception e) { } } } } }
/** * 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(); } } }
public static void fire(RobotController rc) { int radius; try { if (rc.getType() == RobotType.HQ) { radius = 15; Robot[] enemies = rc.senseNearbyGameObjects(Robot.class, radius, rc.getTeam().opponent()); Direction[] dirs = Direction.values(); Robot target = null; int maxValue = 0; for (int k = 0; k < enemies.length; k++) { MapLocation loc = rc.senseRobotInfo(enemies[k]).location; int value = 2; for (int a = 0; a < 8; a++) { try { if (rc.senseObjectAtLocation(loc.add(dirs[a])).getTeam() == rc.getTeam().opponent()) { value++; } else if (rc.senseObjectAtLocation(loc.add(dirs[a])).getTeam() == rc.getTeam()) { value--; } } catch (Exception e) { e.printStackTrace(); } } rc.setIndicatorString(0, "" + value); if (value > maxValue) { maxValue = value; target = enemies[k]; } } if (target != null) { rc.attackSquare(rc.senseRobotInfo(target).location); } } else { radius = 10; Robot[] enemies = rc.senseNearbyGameObjects(Robot.class, radius, rc.getTeam().opponent()); Robot target = null; for (int k = 0; k < enemies.length; k++) { if (target == null) { target = enemies[k]; } else if (rc.senseRobotInfo(enemies[k]).health < rc.senseRobotInfo(target).health) { target = enemies[k]; } } if (target != null) { rc.attackSquare(rc.senseRobotInfo(target).location); } } } catch (Exception e) { e.printStackTrace(); } }
/** * Returns true if no nearby enemies or if the nearby enemies are only scouts. Returns false if * deadly enemies are within sensing radius. * * @return boolean * @param RobotController rc */ private static boolean isNearbyEnemies(RobotController rc) { RobotInfo[] enemies = rc.senseHostileRobots(rc.getLocation(), rc.getType().sensorRadiusSquared); for (int i = 0; i < enemies.length; i++) { if (enemies[i].type != RobotType.SCOUT) { return true; } } return enemies.length > 0; }
static void init(RobotController rc) { int roundLimit = rc.getRoundLimit(); Common.rc = rc; rand = new Random(rc.getID()); id = rc.getID(); myTeam = rc.getTeam(); enemyTeam = myTeam.opponent(); history = new MapLocation[roundLimit]; robotType = rc.getType(); enrollment = rc.getRoundNum(); if (robotType != RobotType.ARCHON) birthday = enrollment - robotType.buildTurns - BUILD_LAG; hometown = rc.getLocation(); sightRadius = robotType.sensorRadiusSquared; straightSight = (int) Math.sqrt(sightRadius); canMessageSignal = robotType.canMessageSignal(); Signals.buildTarget = new MapLocation[roundLimit]; Signals.buildStrategy = new SignalStrategy[roundLimit]; try { addInfo(rc.senseRobot(id)); myArchonHometowns = rc.getInitialArchonLocations(myTeam); enemyArchonHometowns = rc.getInitialArchonLocations(enemyTeam); int coordinates[] = new int[MAP_MAX]; int x = 0; int y = 0; for (int i = enemyArchonHometowns.length - 1; i >= 0; --i) { MapLocation loc = enemyArchonHometowns[i]; twiceCenterX += loc.x; twiceCenterY += loc.y; coordinates[loc.y] *= MAP_MAX; coordinates[loc.y] += loc.x + 1; } for (int i = 0; i < myArchonHometowns.length; ++i) { MapLocation loc = myArchonHometowns[i]; twiceCenterX += loc.x; twiceCenterY += loc.y; x += loc.x; y += loc.y; } twiceCenterX /= myArchonHometowns.length; twiceCenterY /= myArchonHometowns.length; x /= myArchonHometowns.length; y /= myArchonHometowns.length; for (int i = 0; i < myArchonHometowns.length; ++i) { MapLocation loc = myArchonHometowns[i]; int xCoord = coordinates[loc.y] - 1; coordinates[loc.y] /= MAP_MAX; if (loc.x != twiceCenterX - xCoord) rotation = true; } Archon.center = new MapLocation(x, y); myBase = new MapLocation(twiceCenterX / 2, twiceCenterY / 2).directionTo(Archon.center); enemyBase = myBase.opposite(); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
/** * Repairs the first-sensed, injured, allied robot * * @param rc must be an archon * @throws GameActionException */ private static void repairFirst(RobotController rc) throws GameActionException { RobotInfo[] allies = rc.senseNearbyRobots(rc.getType().attackRadiusSquared, myTeam); for (int i = 0; i < allies.length; i++) { if (allies[i].health < allies[i].maxHealth && !allies[i].type.equals(RobotType.ARCHON)) { // can't repair other archons rc.repair(allies[i].location); break; } } }
public Robot(RobotController rc) { this.rc = rc; rand = new Random(rc.getID()); team = rc.getTeam(); enemy = team.opponent(); currentLocation = rc.getLocation(); RobotType type = rc.getType(); senseRadius = type.sensorRadiusSquared; attackRadius = type.attackRadiusSquared; }
private static void turretAttack(RobotController rc) throws GameActionException { if (rc.isWeaponReady()) { // can't attack if enemy is too close so attackFirst throws errors RobotInfo[] enemies = rc.senseHostileRobots(rc.getLocation(), rc.getType().attackRadiusSquared); for (RobotInfo enemy : enemies) { if (rc.canAttackLocation(enemy.location) && rc.isWeaponReady()) { rc.attackLocation(enemy.location); } } } }
/** * If rc has no core delay, attempts to move towards the first allied archon sensed. Does not move * if rc is already within ARCHON_RESERVED_DISTANCE_SQUARED of the archon * * @param rc * @return true if rc moves else false * @throws GameActionException */ private static void moveTowardsArchon(RobotController rc) throws GameActionException { RobotInfo[] nearbyRobots = rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, myTeam); for (int i = 0; i < nearbyRobots.length; i++) { if (nearbyRobots[i].type == (RobotType.ARCHON) && rc.isCoreReady()) { if (nearbyRobots[i].location.distanceSquaredTo(rc.getLocation()) > ARCHON_RESERVED_DISTANCE_SQUARED) { Direction dir = rc.getLocation().directionTo(nearbyRobots[i].location); moveTowards(rc, dir); } } } }
private static void moveAwayFromEnemies(RobotController rc) throws GameActionException { // TODO might want a different value for how far you sense enemies and // do a "center of mass" of enemies weighted by their attack values then // move away from that? RobotInfo[] enemies = rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, myTeam.opponent()); for (int i = 0; i < enemies.length; i++) { if (rc.isCoreReady()) { Direction awayFrom = rc.getLocation().directionTo(enemies[0].location).opposite(); moveTowards(rc, awayFrom); } } }
public static void init(RobotController the_rc) { rc = the_rc; friendly = rc.getTeam(); enemy = friendly.opponent(); neutral = Team.NEUTRAL; zombie = Team.ZOMBIE; current_location = rc.getLocation(); my_type = rc.getType(); byte_code_limiter = my_type.bytecodeLimit; }
/** * Message-processing for non-archons Currently handles messages: Change of mode Setting * turtle-corner location * * @param rc * @throws GameActionException */ private static void processFighterSignals(RobotController rc) throws GameActionException { int cornerX = Integer.MIN_VALUE; int cornerY = Integer.MIN_VALUE; RobotType type = rc.getType(); Signal[] signals = rc.emptySignalQueue(); for (Signal s : signals) { if (s.getTeam().equals(myTeam) && s.getMessage() != null) { final int[] message = s.getMessage(); if (message[0] == SENDING_MODE) { currentMode = message[1]; } else if (message[0] == SENDING_TURTLE_X) { cornerX = message[1]; } else if (message[0] == SENDING_TURTLE_Y) { cornerY = message[1]; } } // when a soldier finds a zombie den, it signals. Other soldiers that receive // the message then should move toward the den to help kill it. Ideally, // this should make it easier to remove zombie dens near the turtle corner if (type == RobotType.SOLDIER && s.getTeam().equals(myTeam) && s.getMessage() == null) { if (rc.getLocation().distanceSquaredTo(s.getLocation()) < rc.getType().sensorRadiusSquared * 2.5 && rc.isCoreReady()) { moveTowards(rc, rc.getLocation().directionTo(s.getLocation())); } } // for turrets to attack broadcasting enemies outside of sight range if (type == RobotType.TURRET && !s.getTeam().equals(myTeam) && rc.isWeaponReady() && rc.canAttackLocation(s.getLocation())) { rc.attackLocation(s.getLocation()); } } if (cornerX > Integer.MIN_VALUE && cornerY > Integer.MIN_VALUE) { turtleCorner = new MapLocation(cornerX, cornerY); } }
public static void run(RobotController rc) { int type = 0; while (true) { try { if (rc.getType() == RobotType.HQ) { new SmartHQ(rc).run(); } else if (rc.getType() == RobotType.NOISETOWER) { new GenericTower(rc, false).run(); } else if (rc.getType() == RobotType.PASTR) { rc.yield(); } else { if (type == 0) { type = rc.readBroadcast(0); } else if (type == SmartHQ.DURAN) { // new Duran(rc).run(); } else if (type == SmartHQ.GHOST) { // new Ghost(rc).run(); } else if (type == SmartHQ.GOLIATH) { // new Goliath(rc).run(); } else if (type == SmartHQ.MARINE) { // new Marines(rc).run(); } else if (type == SmartHQ.MULE) { new fastMULE(rc, true).run(); } else if (type == SmartHQ.TOWER) { new SmartTower(rc, true).run(); } else if (type == SmartHQ.TROLL) { // new Scout(rc).run(); } else if (type == SmartHQ.OPTOWER) { new SmartTower(rc, false).run(); } else if (type == SmartHQ.OPMULE) { new fastMULE(rc, false).run(); } } } catch (Exception e) { } } }
/** * Checks if rc can move in direction dir (runs isCoreReady and canMove). If so, moves. If not, * moves rc in any of the four directions nearest dir, if possible. * * @param rc * @param dir * @return true if rc moves else false * @throws GameActionException */ private static void moveTowards(RobotController rc, Direction dir) throws GameActionException { if (rc.isCoreReady() && !dir.equals(Direction.OMNI) && !dir.equals(Direction.NONE)) { Direction[] moveRight = { dir, dir.rotateRight(), dir.rotateLeft(), dir.rotateRight().rotateRight(), dir.rotateLeft().rotateLeft() }; Direction[] moveLeft = { dir, dir.rotateLeft(), dir.rotateRight(), dir.rotateLeft().rotateLeft(), dir.rotateRight().rotateRight() }; Direction[] nearDirections = Math.random() >= .5 ? moveRight : moveLeft; // 50% chance robot tries to move to right first for (Direction nearDir : nearDirections) { if (rc.canMove(nearDir) && rc.isCoreReady()) { rc.move(nearDir); } } if (rc.getType() != RobotType.TTM && rc.getType() != RobotType.TTM) // these types can't clear rubble { if (rc.isCoreReady() && rc.onTheMap(rc.getLocation().add(dir)) && rc.senseRubble(rc.getLocation().add(dir)) > RUBBLE_LOWER_CLEAR_THRESHOLD) { clearRubble(rc); } } } }
public static void run(RobotController rcIn) throws GameActionException { rc = rcIn; randall.setSeed(rc.getRobot().getID()); if (rc.getType() == RobotType.HQ) { tryToSpawn(); } else { BreadthFirst.init(rc, bigBoxSize); MapLocation goal = getRandomLocation(); path = BreadthFirst.pathTo( VectorFunctions.mldivide(rc.getLocation(), bigBoxSize), VectorFunctions.mldivide(goal, bigBoxSize), 100000); // VectorFunctions.printPath(path,bigBoxSize); } // generate a coarsened map of the world // TODO only HQ should do this. The others should download it. // MapAssessment.assessMap(4); // MapAssessment.printBigCoarseMap(); // MapAssessment.printCoarseMap(); while (true) { try { if (rc.getType() == RobotType.HQ) { runHQ(); } else if (rc.getType() == RobotType.SOLDIER) { runSoldier(); } } catch (Exception e) { // e.printStackTrace(); } rc.yield(); } }
/** * @param rc * @param dirToCorner * @return the location of the corner in the given direction or LOCATION_NONE if it is not a * corner * @throws GameActionException */ private static MapLocation checkForCorner(RobotController rc, Direction dirToCorner) throws GameActionException { int senseRadiusMinusOneSquared = (int) Math.pow(Math.sqrt(rc.getType().sensorRadiusSquared) - 1, 2); // so that when you add one below to check for a corner, you can still sense the +1 location MapLocation[] nearby = MapLocation.getAllMapLocationsWithinRadiusSq(rc.getLocation(), senseRadiusMinusOneSquared); boolean isCorner = true; MapLocation corner = getFurthestInDirection(rc, nearby, dirToCorner); Direction[] nearDirections = {dirToCorner, dirToCorner.rotateLeft(), dirToCorner.rotateRight()}; for (Direction dir : nearDirections) { if (rc.onTheMap(corner.add(dir))) { isCorner = false; } } return isCorner ? corner : LOCATION_NONE; }
private static void runSoldier() throws GameActionException { // follow orders from HQ // Direction towardEnemy = rc.getLocation().directionTo(rc.senseEnemyHQLocation()); // BasicPathing.tryToMove(towardEnemy, true, rc, directionalLooks, allDirections);//was // Direction.SOUTH_EAST Robot[] enemyRobots = rc.senseNearbyGameObjects(Robot.class, 10000, rc.getTeam().opponent()); if (enemyRobots.length > 0) { // if there are enemies rc.setIndicatorString(0, "There are enemies"); MapLocation[] robotLocations = new MapLocation[enemyRobots.length]; for (int i = 0; i < enemyRobots.length; i++) { Robot anEnemy = enemyRobots[i]; RobotInfo anEnemyInfo = rc.senseRobotInfo(anEnemy); robotLocations[i] = anEnemyInfo.location; } MapLocation closestEnemyLoc = VectorFunctions.findClosest(robotLocations, rc.getLocation()); if (closestEnemyLoc.distanceSquaredTo(rc.getLocation()) < rc.getType().attackRadiusMaxSquared) { rc.setIndicatorString(1, "trying to shoot"); if (rc.isActive()) { rc.attackSquare(closestEnemyLoc); } } else { rc.setIndicatorString(1, "trying to go closer"); Direction towardClosest = rc.getLocation().directionTo(closestEnemyLoc); simpleMove(towardClosest); } } else { if (path.size() == 0) { MapLocation goal = getRandomLocation(); path = BreadthFirst.pathTo( VectorFunctions.mldivide(rc.getLocation(), bigBoxSize), VectorFunctions.mldivide(rc.senseEnemyHQLocation(), bigBoxSize), 100000); } // follow breadthFirst path Direction bdir = BreadthFirst.getNextDirection(path, bigBoxSize); BasicPathing.tryToMove(bdir, true, rc, directionalLooks, allDirections); } // Direction towardEnemy = rc.getLocation().directionTo(rc.senseEnemyHQLocation()); // simpleMove(towardEnemy); }
public void probeAndUpdateMapInfoModule( final MapInfoModule mapInfoModule, final MapLocation location, final RobotController robotController) throws GameActionException { final int probeDistance = (int) Math.floor(Math.sqrt(robotController.getType().sensorRadiusSquared)); if (mapInfoModule.eastBoundaryValue == MapInfoModule.UnknownValue) { final MapLocation foundProbeLocation = this.probeDirection(Direction.EAST, probeDistance, location, robotController); if (foundProbeLocation != null) { mapInfoModule.eastBoundaryValue = foundProbeLocation.x; } } if (mapInfoModule.westBoundaryValue == MapInfoModule.UnknownValue) { final MapLocation foundProbeLocation = this.probeDirection(Direction.WEST, probeDistance, location, robotController); if (foundProbeLocation != null) { mapInfoModule.westBoundaryValue = foundProbeLocation.x; } } if (mapInfoModule.northBoundaryValue == MapInfoModule.UnknownValue) { final MapLocation foundProbeLocation = this.probeDirection(Direction.NORTH, probeDistance, location, robotController); if (foundProbeLocation != null) { mapInfoModule.northBoundaryValue = foundProbeLocation.y; } } if (mapInfoModule.southBoundaryValue == MapInfoModule.UnknownValue) { final MapLocation foundProbeLocation = this.probeDirection(Direction.SOUTH, probeDistance, location, robotController); if (foundProbeLocation != null) { mapInfoModule.southBoundaryValue = foundProbeLocation.y; } } }
@SuppressWarnings("fallthrough") static void addInfo(int id, Team team, RobotType robotType, MapLocation loc) throws GameActionException { boolean newLoc = false; // use knownTypes because team, time, and location can come from intercepting signals boolean newRobot = knownTypes[id] == null; knownTeams[id] = team; knownTypes[id] = robotType; if (loc != null && loc.x != MAP_NONE) { // loc.y assumed if (knownLocations[id] == null) newLoc = true; knownTimes[id] = rc.getRoundNum(); knownLocations[id] = loc; } if (rc.getType().canMessageSignal() && (newRobot || newLoc) && rc.getRoundNum() - enrollment > 10) { if (team == Team.NEUTRAL) { SignalUnit s = new SignalUnit(id, team, robotType, loc); s.add(); typeSignals[typeSignalsSize++] = s.toInt(); neutralIds[neutralIdsSize++] = id; neutralTypes[neutralTypesSize++] = robotType; neutralLocations[neutralLocationsSize++] = loc; } else { switch (robotType) { case VIPER: if (team != myTeam) break; case TURRET: case TTM: if (robotType == RobotType.VIPER || team != enemyTeam) break; case ARCHON: case ZOMBIEDEN: case BIGZOMBIE: new SignalUnit(id, team, robotType, loc).add(); if (newRobot) typeSignals[typeSignalsSize++] = new SignalUnit(id, team, robotType).toInt(); break; default: break; } } } }
public static void run(RobotController myRC) { rc = myRC; barracks = findBarracks(); while (true) { try { if (rc.getType() == RobotType.SOLDIER) { Robot[] enemyRobots = rc.senseNearbyGameObjects( Robot.class, 50000, rc.getTeam().opponent()); // list of enemy robots if (enemyRobots.length == 0) { Clock.getRoundNum(); // gets the round number if (Clock.getRoundNum() < 250) { goToLocation( barracks); // if you are before round 250 travel to the "barracks" or meeting // place. } else { goToLocation(rc.senseEnemyHQLocation()); } } else { // else attack the closest enemy int closestDist = 50000; MapLocation closestEnemy = null; for (int i = 0; i < enemyRobots.length; i++) { Robot enemyBot = enemyRobots[i]; RobotInfo arobotInfo = rc.senseRobotInfo(enemyBot); int dist = arobotInfo.location.distanceSquaredTo(rc.getLocation()); if (dist < closestDist) { closestDist = dist; closestEnemy = arobotInfo.location; } } goToLocation(closestEnemy); } } else { HqCommand(); } } catch (Exception e) { e.printStackTrace(); } rc.yield(); // end turn } }