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
4,427 changes: 4,427 additions & 0 deletions java/src/use_all_paint/Attack.java

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions java/src/use_all_paint/Comms.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package use_all_paint;
import battlecode.common.*;

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

public static void run() throws GameActionException {
updateSym();
broadcastSym();
}

public static void updateSym() throws GameActionException {
Message[] m = rc.readMessages(-1);
for (int i = m.length; --i >= 0;) {
int msg = m[i].getBytes();
SymmetryChecker.RSYM &= (msg & 1);
SymmetryChecker.HSYM &= ((msg & 2) >> 1);
SymmetryChecker.VSYM &= ((msg & 4) >> 2);
}
}

public static void broadcastSym() throws GameActionException {
int R = SymmetryChecker.RSYM;
int H = SymmetryChecker.HSYM;
int V = SymmetryChecker.VSYM;
int send = R + 2 * H + 4 * V;
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);
}
}
}
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);
}
}
}
}
}
75 changes: 75 additions & 0 deletions java/src/use_all_paint/Explore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package use_all_paint;
import battlecode.common.*;
import java.util.Stack;

public class Explore {
public static RobotController rc;
public static MapLocation exploreTarget = null;
public static Stack<MapLocation> circle;

//r = 8
//public static int cX[] = {-8, -5, 0, 5, 8, 5, 0, -5};
//public static int cY[] = {0, 6, 8, 6, 0, -6, -8, -6};

public static int cX[] = {-6, -4, 0, 4, 6, 4, 0, -6};
public static int cY[] = {0, 4, 6, 4, 0, -4, -6, -4};

public static void init(RobotController rc) {
Explore.rc = rc;
circle = new Stack<>();
}

public static void exploreOnPaint(MapInfo[] near) throws GameActionException {
explore(near);
}

public static void explore(MapInfo[] near) throws GameActionException {
if (exploreTarget == null || rc.getLocation().distanceSquaredTo(exploreTarget) <= 5) {
/*
if (!circle.isEmpty()) {
exploreTarget = circle.pop();
}
else {
if (Globals.rng.nextInt(3) == 0) {
int st = Globals.rng.nextInt(8);
MapLocation loc;

loc = new MapLocation(rc.getLocation().x + cX[(st + 0) % 8], rc.getLocation().y + cY[(st + 0) % 8]);
if (Globals.onMap(loc)) {
circle.push(loc);
}

loc = new MapLocation(rc.getLocation().x + cX[(st + 1) % 8], rc.getLocation().y + cY[(st + 1) % 8]);
if (Globals.onMap(loc)) {
circle.push(loc);
}

loc = new MapLocation(rc.getLocation().x + cX[(st + 2) % 8], rc.getLocation().y + cY[(st + 2) % 8]);
if (Globals.onMap(loc)) {
circle.push(loc);
}

loc = new MapLocation(rc.getLocation().x + cX[(st + 3) % 8], rc.getLocation().y + cY[(st + 3) % 8]);
if (Globals.onMap(loc)) {
circle.push(loc);
}

exploreTarget = circle.pop();
}
if (exploreTarget == null) {
exploreTarget = new MapLocation(
Globals.rng.nextInt(rc.getMapWidth()),
Globals.rng.nextInt(rc.getMapHeight())
);
}
}
*/
exploreTarget = new MapLocation(
Globals.rng.nextInt(rc.getMapWidth()),
Globals.rng.nextInt(rc.getMapHeight())
);
}
Pathing.pathTo(exploreTarget);
}

}
81 changes: 81 additions & 0 deletions java/src/use_all_paint/Globals.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package use_all_paint;
import java.util.Random;
import battlecode.common.*;

public class Globals {
public static int roundNum;
public static RobotController rc;
public static final Random rng = new Random();
public static boolean[][] moneyTower;
public static boolean[][] paintTower;
public static void init(RobotController rc) throws GameActionException {
rng.setSeed((long) rc.getID());
Globals.rc = rc;
moneyTower = rc.getTowerPattern(UnitType.LEVEL_ONE_MONEY_TOWER);
paintTower = rc.getTowerPattern(UnitType.LEVEL_ONE_PAINT_TOWER);
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();
updateIncomeTracker();
}

public static boolean onMap(MapLocation loc) throws GameActionException {
return (loc.x >= 0 && loc.y >= 0 && loc.x < rc.getMapWidth() && loc.y < rc.getMapHeight());
}

public static UnitType getTowerToBuild(MapLocation loc) throws GameActionException {
MapLocation paintMark = loc.add(Direction.WEST);
MapLocation moneyMark = loc.add(Direction.SOUTH);
if (rc.canSenseLocation(paintMark)){
MapInfo s = rc.senseMapInfo(paintMark);
if (s.getMark() == PaintType.ALLY_SECONDARY) return UnitType.LEVEL_ONE_PAINT_TOWER;
}
if( rc.canSenseLocation(moneyMark)) {
MapInfo s = rc.senseMapInfo(moneyMark);
if (s.getMark() == PaintType.ALLY_SECONDARY) return UnitType.LEVEL_ONE_MONEY_TOWER;
}
if (rc.getMoney() < 2000) return UnitType.LEVEL_ONE_MONEY_TOWER;
return UnitType.LEVEL_ONE_PAINT_TOWER;
}

public static boolean isTower(UnitType u) {
return switch (u) {
case SOLDIER -> false;
case SPLASHER -> false;
case MOPPER -> false;
default -> true;
};
}


// Income Tracking.
public static int born;
public static int income = GameConstants.NUMBER_INITIAL_MONEY_TOWERS * UnitType.LEVEL_ONE_MONEY_TOWER.moneyPerTurn;
public static int lastMoney = 0;
public static int moneyUpdateFreq = 30;
public static void updateIncomeTracker() throws GameActionException {
if (roundNum < moneyUpdateFreq) return;
int modulo = (roundNum % moneyUpdateFreq);
if (modulo == 0) {
lastMoney = rc.getMoney();
} else if (modulo == 1) {
income = (rc.getMoney() - lastMoney);
}
}

public static boolean shouldStallForIncome() throws GameActionException {
if (roundNum < moneyUpdateFreq) return false;
int modulo = (roundNum % moneyUpdateFreq);
return (modulo == 0) || (modulo == 1);
}

public static int getIncome() {
return income;
}
}
Loading