public void play() throws GameActionException { if (rc.isActive()) { int soundChannel = 1; int pastrChannel = 2; Message ms = Comms.ReadMessage(rc, soundChannel); Message mp = Comms.ReadMessage(rc, pastrChannel); if (ms != null) { if (rc.senseObjectAtLocation(ms.loc) == null) { rc.broadcast(soundChannel, 0); } } if (mp != null) { if (rc.senseObjectAtLocation(mp.loc) == null) { rc.broadcast(pastrChannel, 0); } } // in principle the HQ is really good at killing enemies // BUT // killing nearby enemies almost never happens // because the HQ is so busy spawning more robots // and it cant shoot during spawning Tactics.killNearbyEnemiesHQ(rc, info); spawnRobot(); } }
public SoundStrategy(final RobotController rc, Random rand) throws GameActionException { targetList = new ArrayList<MapLocation>(); this.rc = rc; int pastrChannel = 2; Message mp = Comms.ReadMessage(rc, pastrChannel); if (mp != null) { this.pastrLoc = mp.loc; } else { this.pastrLoc = null; } int increment = 2; // int increment=NOISE_SCARE_RANGE_SMALL; // this doesnt seem to exist in GameConstants? // The above strategy is pretty poor. How about two-dimensional forloop // building an array of target MapLocations we can hit. for (int x = 0; x < rc.getMapWidth(); x = x + increment) { for (int y = 0; y < rc.getMapHeight(); y = y + increment) { if (rc.isActive()) { currentTarget = new MapLocation(x, y); if (rc.canAttackSquare(currentTarget)) { targetList.add(currentTarget); // System.out.println("Adding x:" + x + " y:" + y); } } else { rc.yield(); } } } pos = 0; // sort by distance from rc.getLocation() Collections.sort( targetList, new Comparator<MapLocation>() { public int compare(MapLocation b, MapLocation a) { return new Integer(pastrLoc.distanceSquaredTo(a)) .compareTo(pastrLoc.distanceSquaredTo(b)); } }); }