Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions templates/Attack.java.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class Attack {
public static void initTurn() throws GameActionException {
myloc = rc.getLocation();
boolean shouldComputeReachSoon = false;
for (int i = Globals.enemies.length; --i >= 0; ) {
RobotInfo enemy = Globals.enemies[i];
for (int i = Cache.enemies.length; --i >= 0; ) {
RobotInfo enemy = Cache.enemies[i];
switch (enemy.type) {
case SOLDIER, MOPPER, SPLASHER: continue;
default:
Expand Down Expand Up @@ -110,8 +110,8 @@ public class Attack {


public static boolean shouldSoldierMicro() throws GameActionException {
for (int i = Globals.enemies.length; --i >= 0; ) {
RobotInfo enemy = Globals.enemies[i];
for (int i = Cache.enemies.length; --i >= 0; ) {
RobotInfo enemy = Cache.enemies[i];
switch (enemy.type) {
case SOLDIER, MOPPER, SPLASHER: continue;
default: if (canHitSoon(enemy.location)) return true;
Expand All @@ -121,8 +121,8 @@ public class Attack {
}

public static void soldierTryAttack() throws GameActionException {
for (int i = Globals.enemies.length; --i >= 0;) {
RobotInfo enemy = Globals.enemies[i];
for (int i = Cache.enemies.length; --i >= 0;) {
RobotInfo enemy = Cache.enemies[i];
switch (enemy.type) {
case SOLDIER, SPLASHER, MOPPER: continue;
default: {
Expand All @@ -138,8 +138,8 @@ public class Attack {

public static boolean shouldSplasherMicro() throws GameActionException {
// Only activate micro if you can attack a tower.
for (int i = Globals.enemies.length; --i >= 0; ) {
RobotInfo enemy = Globals.enemies[i];
for (int i = Cache.enemies.length; --i >= 0; ) {
RobotInfo enemy = Cache.enemies[i];
switch (enemy.type) {
case SOLDIER, MOPPER, SPLASHER: continue;
default: if (canHitSoon(enemy.location)) return true;
Expand Down Expand Up @@ -200,7 +200,7 @@ public class Attack {
{%- endfor -%}

boolean friendNearby = false;
for (RobotInfo r: Globals.friends) {
for (RobotInfo r: Cache.friends) {
if (r.type == UnitType.SOLDIER) {
friendNearby = true;
break;
Expand All @@ -212,15 +212,15 @@ public class Attack {
boolean actionReady = (rc.isActionReady() && (rc.getPaint() >= 5) && !shouldWaitForFriend);
int cooldownTurns = rc.getActionCooldownTurns();
{# {% debug('actionReady', 'cooldownTurns') %} #}
for (int i = Globals.friends.length; --i >= 0; ) {
RobotInfo robot = Globals.friends[i];
for (int i = Cache.friends.length; --i >= 0; ) {
RobotInfo robot = Cache.friends[i];
{% for i in range(9) -%}
{{ addAlly(type, i) | indent(8) -}}
{% endfor %}
}

for (int i = Globals.enemies.length; --i >= 0; ) {
RobotInfo robot = Globals.enemies[i];
for (int i = Cache.enemies.length; --i >= 0; ) {
RobotInfo robot = Cache.enemies[i];
{% for i in range(9) -%}
{{ addEnemy(type, i) | indent(8) -}}
{% endfor %}
Expand Down
22 changes: 22 additions & 0 deletions templates/Cache.java.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package current;
import java.util.Random;
import battlecode.common.*;

public class Cache {
public static RobotController rc;
public static RobotInfo[] friends;
public static RobotInfo[] enemies;
public static MapLocation[] ruins;
public static MapInfo[] mapInfos;

public static void init(RobotController rc) {
Cache.rc = rc;
}

public static void run() throws GameActionException {
friends = rc.senseNearbyRobots(-1, rc.getTeam());
enemies = rc.senseNearbyRobots(-1, rc.getTeam().opponent());
ruins = rc.senseNearbyRuins(-1);
mapInfos = rc.senseNearbyMapInfos(-1);
}
}
51 changes: 45 additions & 6 deletions templates/Comms.java.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ package current;
import battlecode.common.*;

public class Comms {
public static MapLocation myloc;
public static RobotController rc;
public static void init(RobotController rc) throws GameActionException {
Comms.rc = rc;
}

public static int totalHarassersMade = 0;
public static void run() throws GameActionException {
myloc = rc.getLocation();
if (rc.getRoundNum() % 20 == 0) {
totalHarassersMade = 0;
}
updateSym();
broadcastSym();
}
Expand All @@ -19,30 +25,63 @@ public class Comms {
SymmetryChecker.RSYM &= (msg & 1);
SymmetryChecker.HSYM &= ((msg & 2) >> 1);
SymmetryChecker.VSYM &= ((msg & 4) >> 2);
if (((msg & 8) >> 3) != 0)
Harass.isHarasser = true;
}
}

public static void broadcastSym() throws GameActionException {
int harassersMade = 0;
int R = SymmetryChecker.RSYM;
int H = SymmetryChecker.HSYM;
int V = SymmetryChecker.VSYM;
int send = R + 2 * H + 4 * V;
int harassMessage = send + 8;
boolean shouldMakeHarassers = shouldMakeHarassers();
if (Globals.isTower(rc.getType())) {
if (rc.canBroadcastMessage()) {
rc.broadcastMessage(send);
}
for (int i = Globals.friends.length; --i >= 0;) {
if (rc.canSendMessage(Globals.friends[i].location, send)) {
rc.sendMessage(Globals.friends[i].location, send);
for (int i = Cache.friends.length; --i >= 0;) {
RobotInfo friend = Cache.friends[i];
if ((shouldMakeHarassers)
&& (friend.type == UnitType.SOLDIER)
&& (myloc.distanceSquaredTo(friend.location) <= 9)
&& (harassersMade < 2)) {
if (rc.canSendMessage(friend.location, harassMessage)) {
rc.sendMessage(friend.location, harassMessage);
++harassersMade;
}
} else {
if (rc.canSendMessage(friend.location, send)) {
rc.sendMessage(friend.location, send);
}
}
}
}
else {
for (int i = Globals.friends.length; --i >= 0;) if (Globals.isTower(Globals.friends[i].getType())) {
if (rc.canSendMessage(Globals.friends[i].location, send)) {
rc.sendMessage(Globals.friends[i].location, send);
for (int i = Cache.friends.length; --i >= 0;) if (Globals.isTower(Cache.friends[i].getType())) {
if (rc.canSendMessage(Cache.friends[i].location, send)) {
rc.sendMessage(Cache.friends[i].location, send);
}
}
}
}


public static boolean shouldMakeHarassers() throws GameActionException {
if (rc.getRoundNum() % 20 < 15) return false;
if (totalHarassersMade >= 2) return false;
int soldierCount = 0;
for (int i = Cache.friends.length; --i >= 0;) {
RobotInfo r = Cache.friends[i];
if ((r.type == UnitType.SOLDIER)
&& (rc.canSendMessage(r.location, 0))
&& (myloc.distanceSquaredTo(r.location) <= 9)) {
++soldierCount;
}
}
if (soldierCount >= 2) return true;
return false;
}
}
4 changes: 0 additions & 4 deletions templates/Globals.java.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ public class Globals {
born = rc.getRoundNum();
}

public static RobotInfo[] friends;
public static RobotInfo[] enemies;
public static void run() throws GameActionException {
friends = rc.senseNearbyRobots(-1, rc.getTeam());
enemies = rc.senseNearbyRobots(-1, rc.getTeam().opponent());
roundNum = rc.getRoundNum();
updateTowerTracker();
}
Expand Down
112 changes: 112 additions & 0 deletions templates/Harass.java.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package current;
import battlecode.common.*;

public class Harass {
public static RobotInfo friend = null;
public static RobotController rc;
public static boolean wasHarasser = false;
public static boolean isHarasser = false;
public static boolean reachedH = false;
public static boolean reachedR = false;
public static boolean reachedV = false;
public static boolean seenCenter = false;
public static MapLocation center = null;
public static void init(RobotController rc) throws GameActionException {
Harass.rc = rc;
center = new MapLocation(rc.getMapWidth() / 2, rc.getMapHeight() / 2);
}

public static void initTurn() throws GameActionException {
if (!isHarasser && !wasHarasser) {
isHarasser = decideHarasser();
if (isHarasser) wasHarasser = true;
}

// This should be static...
friend = null;
MapLocation myloc = rc.getLocation();
for (RobotInfo r: Cache.friends) {
if (r.type == UnitType.SOLDIER) {
if (r.location.distanceSquaredTo(myloc) <= 36) {
friend = r;
break;
}
}
}
}

public static boolean decideHarasser() throws GameActionException {
if (rc.getRoundNum() >= 50) return false;
if (rc.getRoundNum() > 5) return false;
if (RefuelManager.home == null) return false;
if (!rc.canSenseLocation(RefuelManager.home)) return false;
RobotInfo r = rc.senseRobotAtLocation(RefuelManager.home);
if (r == null) return false;
if (r.getType() == UnitType.LEVEL_ONE_PAINT_TOWER) return true;
if (r.getType() == UnitType.LEVEL_TWO_PAINT_TOWER) return true;
return false;
}

public static boolean shouldHarass() {
// return (isHarasser) && (friend != null);
return isHarasser;
}

public static void harass() throws GameActionException {
MapLocation myloc = rc.getLocation();
int sym = SymmetryChecker.HSYM + SymmetryChecker.RSYM + SymmetryChecker.VSYM;
if (sym > 1 && !seenCenter) {
if (rc.getLocation().distanceSquaredTo(center) <= 9) seenCenter = true;
else {
Pathing.pathTo(center);
return;
}
}

int closest = 1000000000;
MapLocation best = null;
MapLocation target;
MapLocation ruin = RefuelManager.firstHome;
if (SymmetryChecker.RSYM != 0 && !reachedR) {
target = new MapLocation(rc.getMapWidth() - ruin.x - 1, rc.getMapHeight() - ruin.y - 1);
if (myloc.distanceSquaredTo(target) <= 9) {
reachedR = true;
}
else {
int d = rc.getLocation().distanceSquaredTo(target);
if (d < closest) {
best = target;
closest = d;
}
}
}
if (SymmetryChecker.HSYM != 0 && !reachedH) {
target = new MapLocation(ruin.x, rc.getMapHeight() - ruin.y - 1);
if (myloc.distanceSquaredTo(target) <= 9) {
reachedH = true;
}
else {
int d = rc.getLocation().distanceSquaredTo(target);
if (d < closest) {
best = target;
closest = d;
}
}
}
if (SymmetryChecker.VSYM != 0 && !reachedV) {
target = new MapLocation(rc.getMapWidth() - ruin.x - 1, ruin.y);
if (myloc.distanceSquaredTo(target) <= 9) {
reachedV = true;
}
else {
int d = rc.getLocation().distanceSquaredTo(target);
if (d < closest) {
best = target;
closest = d;
}
}
}
if (best != null) Pathing.pathTo(best);
else isHarasser = false;
}
}
4 changes: 2 additions & 2 deletions templates/Mopper.java.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Mopper {
public static MapLocation mopTarget = null;
public static void computeMopTarget() throws GameActionException {
RobotInfo enemyTower = null;
MapLocation[] ruins = rc.senseNearbyRuins(-1);
MapLocation[] ruins = Cache.ruins;
for (MapLocation loc: ruins) {
RobotInfo r = rc.senseRobotAtLocation(loc);
if (r != null && r.team != rc.getTeam()) {
Expand Down Expand Up @@ -115,7 +115,7 @@ public class Mopper {
public static void initTurn() throws GameActionException {
myloc = rc.getLocation();
myPaint = rc.getPaint();
near = rc.senseNearbyMapInfos();
near = Cache.mapInfos;
computeMopTarget();
RefuelManager.setHome();
boolean lowHealth = (myPaint <= (paintCapacity >> 2));
Expand Down
28 changes: 14 additions & 14 deletions templates/MopperAttack.java.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class MopperAttack {
}

public static boolean shouldMopperMicro() throws GameActionException {
for (int i = Globals.enemies.length; --i >= 0; ) {
if (Globals.enemies[i].paintAmount == 0) continue;
switch (Globals.enemies[i].type) {
for (int i = Cache.enemies.length; --i >= 0; ) {
if (Cache.enemies[i].paintAmount == 0) continue;
switch (Cache.enemies[i].type) {
case SOLDIER, MOPPER, SPLASHER: return true;
default: return false;
}
Expand All @@ -34,19 +34,19 @@ public class MopperAttack {

public static void mopperTryAttack() throws GameActionException {
if ((rc.getPaint() < (UnitType.MOPPER.paintCapacity >> 1))
|| (Globals.enemies.length == 1)) {
|| (Cache.enemies.length == 1)) {
mopperHealAttack();
} else {
mopperMopAttack();
}
}

public static void mopperHealAttack() throws GameActionException {
for (int i = Globals.enemies.length; --i >= 0; ) {
switch (Globals.enemies[i].type) {
for (int i = Cache.enemies.length; --i >= 0; ) {
switch (Cache.enemies[i].type) {
case SOLDIER, MOPPER, SPLASHER: {
if (rc.canAttack(Globals.enemies[i].location)) {
rc.attack(Globals.enemies[i].location);
if (rc.canAttack(Cache.enemies[i].location)) {
rc.attack(Cache.enemies[i].location);
return;
}
}
Expand Down Expand Up @@ -117,24 +117,24 @@ public class MopperAttack {
{%- endfor -%}

boolean shouldChase = true;
for (int i = Globals.enemies.length; --i >= 0; ) {
RobotInfo robot = Globals.enemies[i];
for (int i = Cache.enemies.length; --i >= 0; ) {
RobotInfo robot = Cache.enemies[i];
switch (robot.type) {
case MOPPER -> shouldChase = false;
default -> {}
}
}

boolean actionReady = rc.isActionReady() || shouldChase;
for (int i = Globals.friends.length; --i >= 0; ) {
RobotInfo robot = Globals.friends[i];
for (int i = Cache.friends.length; --i >= 0; ) {
RobotInfo robot = Cache.friends[i];
{% for i in range(9) -%}
{{ addAlly(i) | indent(8) -}}
{% endfor %}
}

for (int i = Globals.enemies.length; --i >= 0; ) {
RobotInfo robot = Globals.enemies[i];
for (int i = Cache.enemies.length; --i >= 0; ) {
RobotInfo robot = Cache.enemies[i];
{% for i in range(9) -%}
{{ addEnemy(i) | indent(8) -}}
{% endfor %}
Expand Down
Loading