Skip to content

Commit

Permalink
walls and ruins not paintable
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Gonzalez Hermosillo committed Jan 3, 2025
1 parent 29d31b9 commit 4891e0a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
30 changes: 15 additions & 15 deletions engine/src/main/battlecode/world/GameWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<MapLocation>();
for (int i = 0; i < numSquares; i++){
if (this.allRuinsByLoc[i]){
this.allRuins.add(indexToLocation(i));
}
}

this.patternArray = gm.getPatternArray();
this.resourcePatternCenters = new ArrayList<MapLocation>();
this.resourcePatternCentersByLoc = new Team[numSquares];
Expand All @@ -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<MapLocation>();
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<MapLocation>();
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;
}
Expand Down Expand Up @@ -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)]));
}
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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<MapLocation> getRuinArray() {
return allRuins;
}
Expand Down
6 changes: 4 additions & 2 deletions engine/src/main/battlecode/world/InternalRobot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions example-bots/src/main/examplefuncsplayer/RobotPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 4891e0a

Please sign in to comment.