private static void shallWeAllIn() throws GameActionException { if (rc.senseEnemyNukeHalfDone() && Clock.getRoundNum() < 300) { rc.broadcast(Constants.attackChannel, Constants.attackAllIn); return; } int massedRobos = 0; double massedAmountNeeded = .5 * (40 + (10 * gencount) - (1 * othercount)); if (rc.senseEnemyNukeHalfDone()) massedAmountNeeded -= 10; int rallyRadius = 33; if (massedAmountNeeded > 50) rallyRadius = 63; Robot[] robos = rc.senseNearbyGameObjects(Robot.class, findRallyPoint(), rallyRadius, rc.getTeam()); for (Robot r : robos) { if (rc.senseRobotInfo(r).type == RobotType.SOLDIER) { ++massedRobos; } } if (massedRobos > massedAmountNeeded) // if we should all in... { rc.broadcast(Constants.attackChannel, Constants.attackAllIn); allInRound = Clock.getRoundNum(); } }
// After a little while, if nothing has gone wrong, if we are next to a pastr and no one // else is building or has built a noise tower, build one. private boolean tryBuildNoiseTower() throws GameActionException { if (!rc.isActive()) return false; if (Clock.getRoundNum() < 200) return false; if (rc.senseRobotCount() < 6) return false; // A problem with building a noise tower is that it makes us more vulnerable to // a rush. If it's early and the opponent hasn't build a pastr, let's hold off // in case it means that they are rushing. if (Clock.getRoundNum() < 300 && rc.sensePastrLocations(them).length == 0) return false; // Only allowed to build noise tower if adjacent to pastr MapLocation[] ourPastrs = rc.sensePastrLocations(us); if (ourPastrs.length == 0 || !here.isAdjacentTo(ourPastrs[0])) return false; // Check if someone else is already building a noise tower MapLocation existingBuilder = MessageBoard.BUILDING_NOISE_TOWER.readMapLocation(); if (existingBuilder != null) { if (rc.senseNearbyGameObjects(Robot.class, existingBuilder, 1, us).length > 0) { return false; } } // Construct the noise tower and advertise the fact that we are doing it MessageBoard.BUILDING_NOISE_TOWER.writeMapLocation(here); constructNoiseTower(ourPastrs[0]); return true; }
public static boolean doWeNeedGenerator() throws GameActionException { if (rc.readBroadcast(Constants.campChannel) == Constants.campGenInProduction) return false; if (Clock.getRoundNum() - allInRound < 80) return false; if (rc.readBroadcast(Constants.commandChannel) == Constants.commandRally && rc.getTeamPower() > powerThreshold) return false; if (rc.getTeamPower() < minPowerThreshold && Clock.getRoundNum() > minRoundThreshold) { return true; } gencount = 0; soldiercount = 0; othercount = 0; Robot[] robos = rc.senseNearbyGameObjects(Robot.class, new MapLocation(0, 0), 1000000, rc.getTeam()); for (Robot r : robos) { RobotType rt = rc.senseRobotInfo(r).type; if (rt == RobotType.GENERATOR) ++gencount; else if (rt == RobotType.SOLDIER) ++soldiercount; else ++othercount; } double decay = .8; if (rc.hasUpgrade(Upgrade.FUSION)) { decay = .99; } if ((40 + (10 * gencount) - (1.6 * soldiercount) - (1 * othercount)) * decay < 1) { return true; } return false; }
public static void timerEnd(String message) { int endBytecodeNum = Clock.getBytecodeNum(); int endRoundNum = Clock.getRoundNum(); if (endRoundNum == startRoundNum) System.out.format( "timed %s: took %d bytecodes\n", message, endBytecodeNum - startBytecodeNum); else System.out.format( "timed %s: took %d turns + %d bytecodes\n", message, endRoundNum - startRoundNum, endBytecodeNum - startBytecodeNum); }
public void run() { while (true) { try { Robot[] enemies = rc.senseNearbyGameObjects(Robot.class, 35, rc.getTeam().opponent()); if (rc.isActive()) { Movement.fire(rc, enemies, null); HQFunctions.SpawnSoldiers(rc); } if (Clock.getRoundNum() % 50 == 0) { System.out.println(); System.out.println("Enemy Bots: "); int[] AllEnemies = FightMicro.AllEnemyBots(rc); for (int i = 0; i < AllEnemies.length; i++) { System.out.print(FightMicro.getBotLocation(AllEnemies[i])); } System.out.println(); } int broadcast = rc.readBroadcast(rallyPoint2); if (broadcast != 0) { if (broadcast != fightZone) { fightZone = broadcast; roundSet = Clock.getRoundNum(); } // now it is time for us to move on else if (roundSet + 75 < Clock.getRoundNum()) { fightZone = 0; rc.broadcast(rallyPoint2, 0); } } if (Clock.getRoundNum() % 5 == 0 && Clock.getRoundNum() > 100) { // HQFunctions.moveTargetLocationRandomly(rc); /* if (goneForPastr && (rc.sensePastrLocations(rc.getTeam()).length > 0 || roundNum > (Clock.getRoundNum() - 250))) { HQFunctions.setTargetLocation(rc, goneForPastr); } else { goneForPastr = HQFunctions.setTargetLocation(rc, goneForPastr); roundNum = Clock.getRoundNum(); }*/ HQFunctions.setTargetLocation(rc, true); // HQFunctions.findInitialRally(rc); } } catch (Exception e) { } rc.yield(); } }
private static void turn() throws GameActionException { if (rc.getHealth() <= 6 * RobotType.SOLDIER.attackPower) { MessageBoard.PASTR_DISTRESS_SIGNAL.writeInt(Clock.getRoundNum()); } // do speculative pathing calculations int bytecodeLimit = 9000; MapLocation[] enemyPastrs = rc.sensePastrLocations(them); for (int i = 0; i < enemyPastrs.length; i++) { if (Clock.getBytecodeNum() > bytecodeLimit) break; Bfs.work(enemyPastrs[i], Bfs.PRIORITY_LOW, bytecodeLimit); } }
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(); } }
// HQ or pastr calls this function to spend spare bytecodes computing paths for soldiers public static void work(MapLocation dest, int priority, int bytecodeLimit) throws GameActionException { int page = findFreePage(dest, priority); Debug.indicate("path", 1, "BFS Pathing to " + dest.toString() + "; using page " + page); if (page == -1) return; // We can't do any work, or don't have to if (!dest.equals(previousDest)) { Debug.indicate("path", 0, "BFS initingQueue"); initQueue(dest); } else { Debug.indicate("path", 0, "BFS queue already inited"); } previousDest = dest; previousRoundWorked = Clock.getRoundNum(); previousPage = page; int mapWidth = rc.getMapWidth(); int mapHeight = rc.getMapHeight(); MapLocation enemyHQ = rc.senseEnemyHQLocation(); boolean destInSpawn = dest.distanceSquaredTo(enemyHQ) <= 25; while (locQueueHead != locQueueTail && Clock.getBytecodeNum() < bytecodeLimit) { // pop a location from the queue MapLocation loc = locQueue[locQueueHead]; locQueueHead++; int locX = loc.x; int locY = loc.y; for (int i = 8; i-- > 0; ) { int x = locX + dirsX[i]; int y = locY + dirsY[i]; if (x >= 0 && y >= 0 && x < mapWidth && y < mapHeight && !wasQueued[x][y]) { MapLocation newLoc = new MapLocation(x, y); if (rc.senseTerrainTile(newLoc) != TerrainTile.VOID && (destInSpawn || !Bot.isInTheirHQAttackRange(newLoc))) { publishResult(page, newLoc, dest, dirs[i]); // push newLoc onto queue locQueue[locQueueTail] = newLoc; locQueueTail++; wasQueued[x][y] = true; } } } } boolean finished = locQueueHead == locQueueTail; Debug.indicate("path", 2, "BFS finished = " + finished + "; locQueueHead = " + locQueueHead); writePageMetadata(page, Clock.getRoundNum(), dest, priority, finished); }
private static void runMissile() { int lastTurn = Clock.getRoundNum() + GameConstants.MISSILE_LIFESPAN; int[] damageRange = {0, 8, 15, 24, 35, 48}; MapLocation target = null; boolean targetMoves = true; while (true) { myLoc = rc.getLocation(); int turns = lastTurn - Clock.getRoundNum(); if (targetMoves) { // Re-acquire the target's location RobotInfo[] inRange = rc.senseNearbyRobots(damageRange[turns], enemyTeam); if (inRange.length > 0) { // No units to target target = inRange[0].location; targetMoves = inRange[0].type.canMove(); rc.setIndicatorString(0, "Missile targetting " + inRange[0].type + "@" + target); } else { targetMoves = false; // Pick a tower or the HQ MapLocation[] enemyTowers = rc.senseEnemyTowerLocations(); for (MapLocation t : enemyTowers) { if (myLoc.distanceSquaredTo(t) <= damageRange[turns]) { target = t; rc.setIndicatorString(0, "Missile targetting Tower @" + target); break; } } if (target == null) { target = rc.senseEnemyHQLocation(); rc.setIndicatorString(0, "Missile targetting HQ @" + target); } } } try { if (target != null) { if (myLoc.distanceSquaredTo(target) <= GameConstants.MISSILE_RADIUS_SQUARED) rc.explode(); else { Direction d = myLoc.directionTo(target); if (rc.canMove(d)) rc.move(d); else if (rc.canMove(d.rotateLeft())) rc.move(d.rotateLeft()); else if (rc.canMove(d.rotateRight())) rc.move(d.rotateRight()); } } } catch (GameActionException e) { System.out.println("Missile exception"); // e.printStackTrace(); } rc.yield(); } }
public class Util { static int m_z = Clock.getBytecodeNum(); static int m_w = Clock.getRoundNum(); /** * Sets up our RNG given two seeds. * * @param seed1 * @param seed2 */ public static void randInit(int seed1, int seed2) { m_z = seed1; m_w = seed2; } private static int gen() { m_z = 36969 * (m_z & 0xFFFF) + (m_z >> 16); m_w = 18000 * (m_w & 0xFFFF) + (m_w >> 16); return (m_w << 16) + m_z; } /** * Returns a random {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE} * * @return */ public static int randInt() { return gen(); } /** * Returns a double between 0 and 1.0 * * @return */ public static double randDouble() { return (gen() * 2.32830644e-10 + 0.5); } /** * Calls randDouble() * * @return */ public static double Random() { return randDouble(); } }
public LinkedList<MapLocation> pathFind(MapLocation start, MapLocation target) throws GameActionException { // for (int i = 0; i < myRobot.allies.length; i++) { // RobotInfo r = rc.senseRobotInfo(myRobot.allies[i]); // if (myRobot.allies[i].getID() == myRobot.ID) continue; // map[r.location.x][r.location.y] = -2; // } // for (int i = 0; i < myRobot.enemies.length; i++) { // RobotInfo r = rc.senseRobotInfo(myRobot.enemies[i]); // map[r.location.x][r.location.y] = -2; // } int x = Clock.getRoundNum(); SearchNode bugSearch = bugSearch(start, target); SearchNode[] nodes = new SearchNode[bugSearch.length]; int counter = bugSearch.length - 1; while (bugSearch.prevLoc != null) { nodes[counter] = bugSearch; bugSearch = bugSearch.prevLoc; counter--; } nodes[0] = bugSearch; LinkedList<MapLocation> pivots = new LinkedList<MapLocation>(); pivots.add(nodes[0].loc); for (int i = 1; i < nodes.length; i++) { if (nodes[i].isPivot) { pivots.add(nodes[i].loc); } } counter = 0; ListIterator<MapLocation> li1 = pivots.listIterator(), li2; while (li1.hasNext()) { li2 = pivots.listIterator(pivots.size()); while (li2.hasPrevious() && li2.previousIndex() > li1.nextIndex() + 1) { if (canTravel(li1.next(), li2.previous())) { pivots.subList(li1.nextIndex(), li2.previousIndex() + 1).clear(); li1 = pivots.listIterator(++counter); break; } li1.previous(); } li1.next(); } if (false) System.out.println(Clock.getRoundNum() - x); return pivots; }
public void fightingCode() throws GameActionException { if (DataCache.numEnemyRobots == 0) { if (DataCache.numAlliedSoldiers < Constants.FIGHTING_NOT_ENOUGH_ALLIED_SOLDIERS) { if (!ourNukeHalfDone && enemyNukeHalfDone) { nextSoldierState = SoldierState.PUSHING; pushingCode(); } else { if (Clock.getRoundNum() >= 200) { nextSoldierState = SoldierState.RALLYING; rallyingCode(); } else { nextSoldierState = SoldierState.PUSHING; pushingCode(); } } } else { nextSoldierState = SoldierState.PUSHING; pushingCode(); } } else { // Otherwise, just keep fighting if (strategy == Strategy.NUKE) { defendMicro(); } else { microCode(); } } }
public static void workOnCache(RobotController rc, int bytecodeLimit) { if (cacheFinished) return; int mapWidth = rc.getMapWidth(); int mapHeight = rc.getMapHeight(); int x, y; if (workStarted) { x = workLocX; y = workLocY; } else { x = mapWidth - 1; y = mapHeight - 1; workStarted = true; } outerloop: while (x >= 0) { while (y >= 0) { terrain[x][y] = rc.senseTerrainTile(new MapLocation(x, y)); y--; // TODO: this is in a tight loop so it would be nice to do this check less often if (Clock.getBytecodeNum() > bytecodeLimit) break outerloop; } y = mapHeight - 1; x--; } workLocX = x; workLocY = y; if (x < 0) cacheFinished = true; }
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()); } }
// Drones private static void runDrone() { moveDir = Direction.NORTH; droneMoveCurrent = 1; droneMoveMax = 2; patrolClockwise = true; droneCentred = false; // We haven't made it to the centre of our spiral yet while (true) { threats.update(); myLoc = rc.getLocation(); // Attack if there is an enemy in sight if (rc.isWeaponReady()) attackWeakest(); // Move if we can and want to if (rc.isCoreReady()) { if (shouldRetreat()) { doRetreatMove(); // Pull back if in range of the enemy guns } else if (Clock.getRoundNum() < 600) { doPatrol(); } else { doSupply(); } } doTransfer(); rc.yield(); } }
// Determines squad of robot to by spawned next private static int nextSquadNum(RobotController rc) throws GameActionException { // If it reads that defensive robots are dying from channel 10 int squad = rc.readBroadcast(Util.spawnNext); if (squad != 0 && squad < 11 && !rush) { rc.broadcast(Util.spawnNext, 0); // reset value // System.out.println("spawning a replacement for defender" + squad); return squad; } // If starting out a rush, spawn enough attacking squads. boolean rushFailed = false; // temporary hot fix - later this should be a checkpoint int rushRetreat = computeRushRetreat(rc); if (rush && Clock.getRoundNum() < rushRetreat && !rushFailed) { // TODO decide when to stop rush for (int i = 11; i < 12; i++) { if ((rc.readBroadcast(i) / 10000) % 10 < 8) return i; } } // Else if didn't establish pastures yet, need defensive squads for (int i = 3; i < 3 + desiredPASTRs.length; i++) { if ((rc.readBroadcast(i) / 10000) % 10 < 6) return i; } // else spawn attackers for (int i = 11; i < 21; i++) { if ((rc.readBroadcast(i) / 10000) % 10 < 6) return i; } return 3; }
public static void continueComputation() { // System.out.println("b" + Clock.getBytecodesLeft()); if (!started) return; while (!que.isEmpty()) { if (Clock.getBytecodesLeft() < 2000) return; MapLocation loc = que.poll().b; if (visited[loc.x][loc.y]) continue; visited[loc.x][loc.y] = true; int thisDist = distances[loc.x][loc.y] + costs[loc.x][loc.y]; int nextX, nextY, dy; for (int dx = -1; dx <= 1; ++dx) for (dy = -1; dy <= 1; ++dy) { nextX = loc.x + dx; nextY = loc.y + dy; if (nextX < 0 || nextX >= gridWidth || nextY < 0 || nextY >= gridHeight) continue; if (distances[nextX][nextY] > thisDist) { distances[nextX][nextY] = thisDist; que.add(Pair.of(thisDist, new MapLocation(nextX, nextY))); parents[nextX][nextY] = loc; } } // System.out.println("c" + Clock.getBytecodesLeft()); } done = true; }
/** * 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(); }
/** * 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(); } } }
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(); } }
public void turn() throws GameActionException { updateStrategicInfo(); // First turn gets special treatment: spawn then do a bunch of computation // (which we devoutly hope will finished before the spawn timer is up // and before anyone attacks us). if (Clock.getRoundNum() == 0) { doFirstTurn(); return; } if (rc.isActive()) { spawnSoldier(); } attackEnemies(); directStrategy(); // Use spare bytecodes to do pathing computations MapLocation pathingDest; if (attackModeTarget != null) pathingDest = attackModeTarget; else if (computedBestPastrLocation != null) pathingDest = computedBestPastrLocation; else pathingDest = null; if (pathingDest != null) Bfs.work(pathingDest, rc, 9000); }
private int findFreePage(MapLocation dest, int priority) throws GameActionException { // see if we can reuse a page we used before if (dest.equals(previousDest) && previousPage != -1) { int previousPageMetadata = readPageMetadata(previousPage); if (getMetadataRoundLastUpdated(previousPageMetadata) == previousRoundWorked) { MapLocation where = getMetadataDestination(previousPageMetadata); if (where.x == cropX(dest.x) && where.y == cropY(dest.y)) { if (getMetadataIsFinished(previousPageMetadata)) { if (getMetadataIsComplete(previousPageMetadata)) return -1; // we're done! don't do any work! // Restart the search with more up to data map info initQueue(dest); // System.out.print("Restart BFS to " + dest + ", page " + previousPage+ ", start round // " + Clock.getRoundNum() + "\n"); return previousPage; } else { return previousPage; } } } } // Check to see if anyone else is working on this destination. If so, don't bother doing // anything. // But as we loop over pages, look for the page that hasn't been touched in the longest time int lastRound = Clock.getRoundNum() - 1; int oldestPage = -1; int oldestPageRoundUpdated = 999999; for (int page = 0; page < NUM_PAGES; page++) { int metadata = readPageMetadata(page); if (metadata == 0) { // untouched page if (oldestPageRoundUpdated > 0) { oldestPage = page; oldestPageRoundUpdated = 0; } } else { int roundUpdated = getMetadataRoundLastUpdated(metadata); boolean isFinished = getMetadataIsFinished(metadata); if (roundUpdated >= lastRound || isFinished) { if (cropSame(getMetadataDestination(metadata), dest)) { return -1; // someone else is on the case! } } if (roundUpdated < oldestPageRoundUpdated) { oldestPageRoundUpdated = roundUpdated; oldestPage = page; } } } // No one else is working on our dest. If we found an inactive page, use that one. if (oldestPage != -1 && oldestPageRoundUpdated < lastRound) return oldestPage; // If there aren't any inactive pages, and we have high priority, just trash page 0: if (priority == PRIORITY_HIGH) return 0; // otherwise, give up: return -1; }
private static void viper(RobotController rc) { // in case we use vipers later // do one time things here while (true) { rc.disintegrate(); Clock.yield(); } }
// returns the number of enemy/allied robots if a robot were to go in each direction. // number of allied is in 10s place, number of enemies is in 1s, a 100 means the direction is // blocked public static int[] getNeighborStats(int badLocs) throws GameActionException { // TODO: Remove this int a = Clock.getBytecodesLeft(); Robot[] NearbyRobots = mRC.senseNearbyGameObjects( Robot.class, 2 * 2 + 2 * 2, ARobot.mEnemy); // 2 in either direction MapLocation roboLoc = mRC.getLocation(); // This array is NUM_DIR + 1 0s, the +1 is for the not moving location int[] eachDirectionStats = {0, 0, 0, 0, 0, 0, 0, 0, 0}; ArrayList<LocationAndIndex> directionLocs = new ArrayList<LocationAndIndex>(); Direction tempDir; // Initialize all the locations for (int i = 0; i < NUM_DIR; i++) { tempDir = Direction.values()[i]; if (mRC.canMove(tempDir) && ((badLocs >> i) & 1) != 1) { directionLocs.add(new LocationAndIndex(roboLoc.add(tempDir), i)); } else { eachDirectionStats[i] = 100; // This signifies the spot is not movable } } // Go through all the robots and see if they're near any of the squares next to us MapLocation tempLocation = null; for (Robot r : NearbyRobots) { tempLocation = mRC.senseRobotInfo(r).location; for (LocationAndIndex mp : directionLocs) { if (tempLocation.distanceSquaredTo(mp.mp) < 2) { // 2 means directly next to us eachDirectionStats[mp.i] += 1; } } if (tempLocation.distanceSquaredTo(roboLoc) < 2) { eachDirectionStats[NUM_DIR] += 1; } } mRC.setIndicatorString(1, "bytecode used for neighbor: " + (a - Clock.getBytecodesLeft())); return eachDirectionStats; }
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 } }
public void enemyInSight( MapLocation[] locations, int[] ints, String[] strings, int locationStart, int intStart, int stringStart, int count) { closestEnemySeen = Clock.getRoundNum(); closestEnemy = navigation.findClosest(locations, locationStart); }
/////////////////////////////////////////////////////////// // 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(); }
public static void run(RobotController _rc) throws GameActionException { Bot.init(_rc); init(); while (true) { myLocation = rc.getLocation(); Radio.process(); action(); Radio.clear(); Clock.yield(); } }
public void herdInward() throws GameActionException { radius = 20 - Math.min(13, (Clock.getRoundNum() % 120) * 16.0 / 120.0); MapLocation target = new MapLocation( (int) (here.x + radius * Math.cos(angle)), (int) (here.y + radius * Math.sin(angle))); angle += rate; rc.setIndicatorString(0, "angle = " + angle); if (rc.canAttackSquare(target)) { rc.attackSquare(target); } }