public static void fireCircle(RobotController rc, int radius, MapLocation center) { for (int k = 0; k < directions.length; k++) { while (!rc.isActive()) {} MapLocation toFire = center.add(directions[k], radius); try { if (toFire.x >= 0 && toFire.x < rc.getMapWidth() && toFire.y >= 0 && toFire.y < rc.getMapHeight()) { rc.attackSquare(toFire); rc.yield(); } } catch (Exception e) { } while (!rc.isActive()) {} toFire = center; for (int a = 0; a < radius / 2; a++) { toFire = toFire.add(directions[k]); toFire = toFire.add(directions[(k + 1) % directions.length]); } try { if (toFire.x >= 0 && toFire.x < rc.getMapWidth() && toFire.y >= 0 && toFire.y < rc.getMapHeight()) { rc.attackSquare(toFire); rc.yield(); } } catch (Exception e) { } } }
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(); } }
public boolean fire() { if (target == null) return false; if (rc.isAttackActive()) return false; if (!rc.canAttackSquare(target.location)) return false; try { rc.attackSquare(target.location, target.type.level); } catch (GameActionException e) { e.printStackTrace(); return false; } return true; }
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 static void pullInto(RobotController rc, int radius, MapLocation center) { for (int k = 0; k < directions.length; k++) { while (!rc.isActive()) {} MapLocation toFire = center.add(directions[k], radius); try { while (toFire.distanceSquaredTo(center) > 3) { if (toFire.x >= 0 && toFire.x < rc.getMapWidth() && toFire.y >= 0 && toFire.y < rc.getMapHeight()) { try { rc.attackSquare(toFire); rc.yield(); } catch (Exception e) { } } toFire = toFire.add(directions[k].opposite()); } } catch (Exception e) { } } }