/** Called every round. */ @Override public void run() throws GameActionException { while (!RC.isActive()) { RC.yield(); } Robot[] robots = Utils.RC.senseNearbyGameObjects(Robot.class, 35, ENEMY_TEAM); Utils.RC.setIndicatorString(1, "" + robots.length); for (int i = 0; i < robots.length; ++i) { messagingSystem.writeAttackMessage(Utils.RC.senseRobotInfo(robots[i]).location); messagingSystem.writeMicroMessage(Utils.RC.senseRobotInfo(robots[i]).location, 1); } makeSomeNoise(); }
public NoiseTowerBehavior() { for (int i = 7; i >= 0; i--) { int lastdir = (i + 4) % 8; int at = 1; paths[i][0] = currentLocation; int lastcow = 0; for (int j = 1; j < 30; j++) { if (i < 7 && RC.isActive()) { try { makeSomeNoise(); } catch (GameActionException e1) { e1.printStackTrace(); } } int k = lastdir + 2; k %= 8; int bestscore = -1; MapLocation bestplace = currentLocation; while (k != (lastdir + 6) % 8) { int score = Math.abs(i - k); if (score < 4) score = 8 - score; score *= score * score; MapLocation here = paths[i][j - 1].add(directions[k]); double cows; try { cows = Utils.COW_GROWTH[here.x][here.y]; if (cows > 0) lastcow = j; score = (here.add(directions[k])).distanceSquaredTo(currentLocation) > 300 || RC.senseTerrainTile(here) == TerrainTile.VOID ? -10 : cows == 0.0 ? 30 : score + (int) (cows) * 0 + 30; } catch (Exception e) { score = -2; } if (score > bestscore) { bestscore = score; bestplace = here; } k++; if (k == 8) k = 0; } if (!bestplace.equals(currentLocation)) { paths[i][j] = bestplace; } else { break; } } pathat[i] = lastcow; while (paths[i][pathat[i]] == null && pathat[i] > 0) pathat[i]--; if (lastcow < 29) lastcow++; } skip[0] = false; double[] d = new double[8]; int[] dist = new int[8]; MapLocation[] toconsider = new MapLocation[8]; for (int i = 7; i >= 0; i--) { if (pathat[i] == 0) { d[i] = 0; dist[i] = 0; } else { toconsider[i] = paths[i][pathat[i] - 1]; d[i] = Math.atan2(toconsider[i].y - curY, toconsider[i].x - curX); dist[i] = currentLocation.distanceSquaredTo(toconsider[i]); } } for (int i = 7; i >= 0; i--) { if (dist[i] == 0) skip[i] = true; else { for (int j = i - 1; j >= 0; j--) { if (i == j || dist[j] == 0) continue; if (Math.abs(d[i] - d[j]) < 0.4 && pathbetween(toconsider[i], toconsider[j])) { if (dist[i] < dist[j]) skip[i] = true; else skip[j] = true; } } } } }
public BFSNoiseTower() throws GameActionException { System.out.println("start " + Clock.getBytecodeNum()); queue[0] = currentLocation; dir[17][17] = Direction.OMNI; for (int i = 7; i >= 0; i--) { Direction d = directions[i]; MapLocation loc = currentLocation.add(d); TerrainTile there = RC.senseTerrainTile(loc); if (!there.isTraversableAtHeight(RobotLevel.ON_GROUND)) continue; int x = loc.x - currentLocation.x; int y = loc.y - currentLocation.y; dir[x + 17][y + 17] = d.opposite(); queue[at] = loc; at++; } for (int s = 1; s < at; s++) { if (s % 30 == 0 && RC.isActive()) { if (target == null || target.distanceSquaredTo(ALLY_PASTR_COUNT > 0 ? ALLY_PASTR_LOCS[0] : currentLocation) <= 5) { earlyNearbyCows(); } MapLocation realTarget = target.add(currentLocation.directionTo(target), 3); if (RC.canAttackSquare(realTarget)) RC.attackSquare(realTarget); target = target.add(target.directionTo(currentLocation)); } Direction initD = dir[queue[s].x - currentLocation.x + 17][queue[s].y - currentLocation.y + 17]; Direction aD; Direction bD; if (initD.isDiagonal()) { aD = initD.rotateLeft().rotateLeft(); bD = initD.rotateRight(); } else { aD = initD.rotateLeft().rotateLeft().rotateLeft(); bD = initD.rotateRight().rotateRight(); } for (Direction d = aD; d != bD; d = d.rotateLeft()) { MapLocation loc = queue[s].add(d); TerrainTile there = RC.senseTerrainTile(loc); if (!there.isTraversableAtHeight(RobotLevel.ON_GROUND)) continue; int x = loc.x - currentLocation.x; int y = loc.y - currentLocation.y; if (x * x + y * y > 200) continue; if (dir[x + 17][y + 17] == null) { dir[x + 17][y + 17] = d.opposite(); queue[at] = loc; at++; } } } System.out.println("end " + Clock.getBytecodeNum()); System.out.println("at " + at); }