private static Direction getScoutTargetDirection(RobotController rc) { Signal[] signals = rc.emptySignalQueue(); for (Signal signal : signals) { if (signal.getMessage() != null && signal.getTeam().equals(myTeam)) { if (signal.getMessage()[0] == SENDING_TARGET_DIRECTION) { return SIGNAL_TO_DIRECTION.get(signal.getMessage()[1]); } } } return Direction.NONE; }
/** * 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); } }
/** * To be run by archons during the intro phase (and others? change it a bit?) to handle and gather * information from incoming message signals * * @param rc */ private static void processIntroMessageSignals(RobotController rc) { int cornerX = Integer.MIN_VALUE; int cornerY = Integer.MIN_VALUE; int denX = Integer.MIN_VALUE; int denY = Integer.MIN_VALUE; 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_CORNER_X) { cornerX = message[1]; } else if (message[0] == SENDING_CORNER_Y) { cornerY = message[1]; } else if (message[0] == SENDING_DEN_X) { denX = message[1]; } else if (message[0] == SENDING_DEN_Y) { denY = message[1]; } } } if (cornerX > Integer.MIN_VALUE && cornerY > Integer.MIN_VALUE) { MapLocation newCorner = new MapLocation(cornerX, cornerY); if (!SCOUTED_CORNERS.contains(newCorner)) { SCOUTED_CORNERS.add(newCorner); rc.setIndicatorString(0, "Added new corner: " + newCorner); rc.setIndicatorString(2, "Current Mode" + currentMode); } rc.setIndicatorString(1, SCOUTED_CORNERS + ""); } if (denX > Integer.MIN_VALUE && denY > Integer.MIN_VALUE) { MapLocation newDen = new MapLocation(denX, denY); if (!ZOMBIE_DEN_LOCATIONS.contains(newDen)) { ZOMBIE_DEN_LOCATIONS.add(newDen); } } }
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(); } }