diff --git a/engine/src/main/battlecode/world/GameWorld.java b/engine/src/main/battlecode/world/GameWorld.java index c7df9643..a5f2b0f2 100644 --- a/engine/src/main/battlecode/world/GameWorld.java +++ b/engine/src/main/battlecode/world/GameWorld.java @@ -98,6 +98,14 @@ public GameWorld(LiveMap gm, RobotControlProvider cp, GameMaker.MatchMaker match // Write match header at beginning of match this.matchMaker.makeMatchHeader(this.gameMap); + this.allRuinsByLoc = gm.getRuinArray(); + this.allRuins = new ArrayList(); + for (int i = 0; i < numSquares; i++){ + if (this.allRuinsByLoc[i]){ + this.allRuins.add(indexToLocation(i)); + } + } + this.patternArray = gm.getPatternArray(); this.resourcePatternCenters = new ArrayList(); this.resourcePatternCentersByLoc = new Team[numSquares]; @@ -107,21 +115,11 @@ public GameWorld(LiveMap gm, RobotControlProvider cp, GameMaker.MatchMaker match setPaint(indexToLocation(i), initialPaint[i]); } - this.allRuinsByLoc = gm.getRuinArray(); - this.allRuins = new ArrayList(); - for (int i = 0; i < numSquares; i++){ - if (this.allRuinsByLoc[i]){ - this.allRuins.add(indexToLocation(i)); - } - } - for (MapLocation ruin : this.allRuins){ - this.allRuinsByLoc[locationToIndex(ruin)] = true; - } RobotInfo[] initialBodies = gm.getInitialBodies(); this.towerLocations = new ArrayList(); - this.towersByLoc = new Team[numSquares]; //idk if both of these are used but I instantiated for now + this.towersByLoc = new Team[numSquares]; for (int i = 0; i < numSquares; i++){ towersByLoc[i] = Team.NEUTRAL; } @@ -407,6 +405,7 @@ public boolean getWall(MapLocation loc) { } public void setPaint(MapLocation loc, int paint) { + if (!isPaintable(loc)) return; if (teamFromPaint(this.colorLocations[locationToIndex(loc)]) != Team.NEUTRAL){ this.getTeamInfo().addPaintedSquares(-1, teamFromPaint(this.colorLocations[locationToIndex(loc)])); } @@ -432,6 +431,7 @@ public int getMarker(Team team, MapLocation loc) { } public void setMarker(Team team, MapLocation loc, int marker) { + if (!isPaintable(loc)) return; if (marker == 0){ this.matchMaker.addUnmarkAction(loc); } @@ -444,13 +444,9 @@ public void setMarker(Team team, MapLocation loc, int marker) { public void markPattern(int pattern, Team team, MapLocation center, int rotationAngle, boolean reflect, boolean isTowerPattern) { for (int dx = -GameConstants.PATTERN_SIZE / 2; dx < (GameConstants.PATTERN_SIZE + 1) / 2; dx++) { for (int dy = -GameConstants.PATTERN_SIZE / 2; dy < (GameConstants.PATTERN_SIZE + 1) / 2; dy++) { - // don't try marking a center ruin - if (dx == 0 && dy == 0 && isTowerPattern) - continue; int symmetry = 4 * (reflect ? 1 : 0) + rotationAngle; int dx2; int dy2; - switch (symmetry) { case 0: dx2 = dx; @@ -565,6 +561,10 @@ public boolean isPassable(MapLocation loc) { return !(this.walls[locationToIndex(loc)] || this.hasRuin(loc)); } + public boolean isPaintable(MapLocation loc){ + return isPassable(loc); + } + public ArrayList getRuinArray() { return allRuins; } diff --git a/engine/src/main/battlecode/world/InternalRobot.java b/engine/src/main/battlecode/world/InternalRobot.java index a3cb48bb..f7806762 100644 --- a/engine/src/main/battlecode/world/InternalRobot.java +++ b/engine/src/main/battlecode/world/InternalRobot.java @@ -344,7 +344,8 @@ public void soldierAttack(MapLocation loc, boolean useSecondaryColor) { } } else { // otherwise, maybe paint // If the tile is empty or same team paint, paint it - if(this.gameWorld.getPaint(loc) == 0 || this.gameWorld.teamFromPaint(paintType) == this.gameWorld.teamFromPaint(this.gameWorld.getPaint(loc))) { + if(this.gameWorld.isPaintable(loc) && + (this.gameWorld.getPaint(loc) == 0 || this.gameWorld.teamFromPaint(paintType) == this.gameWorld.teamFromPaint(this.gameWorld.getPaint(loc)))) { this.gameWorld.setPaint(loc, paintType); this.gameWorld.getMatchMaker().addPaintAction(loc, useSecondaryColor); } @@ -375,6 +376,7 @@ public void splasherAttack(MapLocation loc, boolean useSecondaryColor) { } } else { // otherwise, maybe paint // If the tile is empty or same team paint, paint it + if (!this.gameWorld.isPaintable(loc)) continue; if(this.gameWorld.getPaint(loc) == 0 || this.gameWorld.teamFromPaint(paintType) == this.gameWorld.teamFromPaint(this.gameWorld.getPaint(loc))) { this.gameWorld.setPaint(loc, paintType); this.gameWorld.getMatchMaker().addPaintAction(loc, useSecondaryColor); @@ -411,7 +413,7 @@ public void mopperAttack(MapLocation loc, boolean useSecondaryColor) { } // Either way, mop this tile if it has enemy paint - if(this.gameWorld.teamFromPaint(paintType) != this.gameWorld.teamFromPaint(this.gameWorld.getPaint(loc))) { + if(this.gameWorld.isPaintable(loc) && this.gameWorld.teamFromPaint(paintType) != this.gameWorld.teamFromPaint(this.gameWorld.getPaint(loc))) { this.gameWorld.setPaint(loc, 0); this.gameWorld.getMatchMaker().addUnpaintAction(loc); } diff --git a/example-bots/src/main/examplefuncsplayer/RobotPlayer.java b/example-bots/src/main/examplefuncsplayer/RobotPlayer.java index ebcbf94d..8f842064 100644 --- a/example-bots/src/main/examplefuncsplayer/RobotPlayer.java +++ b/example-bots/src/main/examplefuncsplayer/RobotPlayer.java @@ -153,8 +153,9 @@ public static void runSoldier(RobotController rc) throws GameActionException{ Direction dir = rc.getLocation().directionTo(targetLoc); if (rc.canMove(dir)) rc.move(dir); - // Mark the pattern we need to draw to build a tower here. - if (curRuin.getMark() == PaintType.EMPTY && rc.canMarkTowerPattern(targetLoc)){ + // Mark the pattern we need to draw to build a tower here if we haven't already. + MapLocation shouldBeMarked = curRuin.getMapLocation().subtract(dir); + if (rc.senseMapInfo(shouldBeMarked).getMark() == PaintType.EMPTY && rc.canMarkTowerPattern(targetLoc)){ rc.markTowerPattern(UnitType.LEVEL_ONE_PAINT_TOWER, targetLoc); System.out.println("Trying to build a tower at " + targetLoc); }