Skip to content

Commit 4891e0a

Browse files
author
Ian Gonzalez Hermosillo
committed
walls and ruins not paintable
1 parent 29d31b9 commit 4891e0a

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

engine/src/main/battlecode/world/GameWorld.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ public GameWorld(LiveMap gm, RobotControlProvider cp, GameMaker.MatchMaker match
9898
// Write match header at beginning of match
9999
this.matchMaker.makeMatchHeader(this.gameMap);
100100

101+
this.allRuinsByLoc = gm.getRuinArray();
102+
this.allRuins = new ArrayList<MapLocation>();
103+
for (int i = 0; i < numSquares; i++){
104+
if (this.allRuinsByLoc[i]){
105+
this.allRuins.add(indexToLocation(i));
106+
}
107+
}
108+
101109
this.patternArray = gm.getPatternArray();
102110
this.resourcePatternCenters = new ArrayList<MapLocation>();
103111
this.resourcePatternCentersByLoc = new Team[numSquares];
@@ -107,21 +115,11 @@ public GameWorld(LiveMap gm, RobotControlProvider cp, GameMaker.MatchMaker match
107115
setPaint(indexToLocation(i), initialPaint[i]);
108116
}
109117

110-
this.allRuinsByLoc = gm.getRuinArray();
111-
this.allRuins = new ArrayList<MapLocation>();
112-
for (int i = 0; i < numSquares; i++){
113-
if (this.allRuinsByLoc[i]){
114-
this.allRuins.add(indexToLocation(i));
115-
}
116-
}
117118

118-
for (MapLocation ruin : this.allRuins){
119-
this.allRuinsByLoc[locationToIndex(ruin)] = true;
120-
}
121119

122120
RobotInfo[] initialBodies = gm.getInitialBodies();
123121
this.towerLocations = new ArrayList<MapLocation>();
124-
this.towersByLoc = new Team[numSquares]; //idk if both of these are used but I instantiated for now
122+
this.towersByLoc = new Team[numSquares];
125123
for (int i = 0; i < numSquares; i++){
126124
towersByLoc[i] = Team.NEUTRAL;
127125
}
@@ -407,6 +405,7 @@ public boolean getWall(MapLocation loc) {
407405
}
408406

409407
public void setPaint(MapLocation loc, int paint) {
408+
if (!isPaintable(loc)) return;
410409
if (teamFromPaint(this.colorLocations[locationToIndex(loc)]) != Team.NEUTRAL){
411410
this.getTeamInfo().addPaintedSquares(-1, teamFromPaint(this.colorLocations[locationToIndex(loc)]));
412411
}
@@ -432,6 +431,7 @@ public int getMarker(Team team, MapLocation loc) {
432431
}
433432

434433
public void setMarker(Team team, MapLocation loc, int marker) {
434+
if (!isPaintable(loc)) return;
435435
if (marker == 0){
436436
this.matchMaker.addUnmarkAction(loc);
437437
}
@@ -444,13 +444,9 @@ public void setMarker(Team team, MapLocation loc, int marker) {
444444
public void markPattern(int pattern, Team team, MapLocation center, int rotationAngle, boolean reflect, boolean isTowerPattern) {
445445
for (int dx = -GameConstants.PATTERN_SIZE / 2; dx < (GameConstants.PATTERN_SIZE + 1) / 2; dx++) {
446446
for (int dy = -GameConstants.PATTERN_SIZE / 2; dy < (GameConstants.PATTERN_SIZE + 1) / 2; dy++) {
447-
// don't try marking a center ruin
448-
if (dx == 0 && dy == 0 && isTowerPattern)
449-
continue;
450447
int symmetry = 4 * (reflect ? 1 : 0) + rotationAngle;
451448
int dx2;
452449
int dy2;
453-
454450
switch (symmetry) {
455451
case 0:
456452
dx2 = dx;
@@ -565,6 +561,10 @@ public boolean isPassable(MapLocation loc) {
565561
return !(this.walls[locationToIndex(loc)] || this.hasRuin(loc));
566562
}
567563

564+
public boolean isPaintable(MapLocation loc){
565+
return isPassable(loc);
566+
}
567+
568568
public ArrayList<MapLocation> getRuinArray() {
569569
return allRuins;
570570
}

engine/src/main/battlecode/world/InternalRobot.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ public void soldierAttack(MapLocation loc, boolean useSecondaryColor) {
344344
}
345345
} else { // otherwise, maybe paint
346346
// If the tile is empty or same team paint, paint it
347-
if(this.gameWorld.getPaint(loc) == 0 || this.gameWorld.teamFromPaint(paintType) == this.gameWorld.teamFromPaint(this.gameWorld.getPaint(loc))) {
347+
if(this.gameWorld.isPaintable(loc) &&
348+
(this.gameWorld.getPaint(loc) == 0 || this.gameWorld.teamFromPaint(paintType) == this.gameWorld.teamFromPaint(this.gameWorld.getPaint(loc)))) {
348349
this.gameWorld.setPaint(loc, paintType);
349350
this.gameWorld.getMatchMaker().addPaintAction(loc, useSecondaryColor);
350351
}
@@ -375,6 +376,7 @@ public void splasherAttack(MapLocation loc, boolean useSecondaryColor) {
375376
}
376377
} else { // otherwise, maybe paint
377378
// If the tile is empty or same team paint, paint it
379+
if (!this.gameWorld.isPaintable(loc)) continue;
378380
if(this.gameWorld.getPaint(loc) == 0 || this.gameWorld.teamFromPaint(paintType) == this.gameWorld.teamFromPaint(this.gameWorld.getPaint(loc))) {
379381
this.gameWorld.setPaint(loc, paintType);
380382
this.gameWorld.getMatchMaker().addPaintAction(loc, useSecondaryColor);
@@ -411,7 +413,7 @@ public void mopperAttack(MapLocation loc, boolean useSecondaryColor) {
411413
}
412414

413415
// Either way, mop this tile if it has enemy paint
414-
if(this.gameWorld.teamFromPaint(paintType) != this.gameWorld.teamFromPaint(this.gameWorld.getPaint(loc))) {
416+
if(this.gameWorld.isPaintable(loc) && this.gameWorld.teamFromPaint(paintType) != this.gameWorld.teamFromPaint(this.gameWorld.getPaint(loc))) {
415417
this.gameWorld.setPaint(loc, 0);
416418
this.gameWorld.getMatchMaker().addUnpaintAction(loc);
417419
}

example-bots/src/main/examplefuncsplayer/RobotPlayer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ public static void runSoldier(RobotController rc) throws GameActionException{
153153
Direction dir = rc.getLocation().directionTo(targetLoc);
154154
if (rc.canMove(dir))
155155
rc.move(dir);
156-
// Mark the pattern we need to draw to build a tower here.
157-
if (curRuin.getMark() == PaintType.EMPTY && rc.canMarkTowerPattern(targetLoc)){
156+
// Mark the pattern we need to draw to build a tower here if we haven't already.
157+
MapLocation shouldBeMarked = curRuin.getMapLocation().subtract(dir);
158+
if (rc.senseMapInfo(shouldBeMarked).getMark() == PaintType.EMPTY && rc.canMarkTowerPattern(targetLoc)){
158159
rc.markTowerPattern(UnitType.LEVEL_ONE_PAINT_TOWER, targetLoc);
159160
System.out.println("Trying to build a tower at " + targetLoc);
160161
}

0 commit comments

Comments
 (0)