Skip to content

Commit f1c13ae

Browse files
Merge remote-tracking branch 'origin/engine-day-2'
2 parents 82f5ed3 + dbc355e commit f1c13ae

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

engine/src/main/battlecode/common/UnitType.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package battlecode.common;
22

33
public enum UnitType {
4-
SOLDIER(200, 250, 5, 250, -1, 200, 10, 20, 20, -1, 0, 0),
5-
SPLASHER(300, 400, 50, 150, -1, 300, 50, 9, -1, 50, 0, 0),
4+
SOLDIER(200, 250, 5, 250, -1, 200, 10, 9, 20, -1, 0, 0),
5+
SPLASHER(300, 400, 50, 150, -1, 300, 50, 8, -1, 50, 0, 0),
66
MOPPER(100, 300, 0, 50, -1, 100, 30, 2, -1, -1, 0, 0),
77

8-
LEVEL_ONE_PAINT_TOWER(0, 25, 0, 1000, 1, 1000, 10, 9, 20, 10, 5, 0),
8+
LEVEL_ONE_PAINT_TOWER(0, 100, 0, 1000, 1, 1000, 10, 9, 20, 10, 5, 0),
99
LEVEL_TWO_PAINT_TOWER(0, 250, 0, 1500, 2, 1000, 10, 9, 20, 10, 10, 0),
1010
LEVEL_THREE_PAINT_TOWER(0, 500, 0, 2000, 3, 1000, 10, 9, 20, 10, 15, 0),
1111

12-
LEVEL_ONE_MONEY_TOWER(0, 25, 0, 1000, 1, 1000, 10, 9, 20, 10, 0, 10),
12+
LEVEL_ONE_MONEY_TOWER(0, 100, 0, 1000, 1, 1000, 10, 9, 20, 10, 0, 10),
1313
LEVEL_TWO_MONEY_TOWER(0, 250, 0, 1500, 2, 1000, 10, 9, 20, 10, 0, 15),
1414
LEVEL_THREE_MONEY_TOWER(0, 500, 0, 2000, 3, 1000, 10, 9, 20, 10, 0, 20),
1515

16-
LEVEL_ONE_DEFENSE_TOWER(0, 25, 0, 2500, 1, 1000, 10, 20, 60, 30, 0, 0),
16+
LEVEL_ONE_DEFENSE_TOWER(0, 100, 0, 2500, 1, 1000, 10, 20, 60, 30, 0, 0),
1717
LEVEL_TWO_DEFENSE_TOWER(0, 250, 0, 3000, 2, 1000, 10, 20, 65, 35, 0, 0),
1818
LEVEL_THREE_DEFENSE_TOWER(0, 500, 0, 3500, 3, 1000, 10, 20, 70, 40, 0, 0);
1919

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public static LiveMap deserialize(battlecode.schema.GameMap raw, boolean teamsRe
236236
int[] patternArray = new int[4];
237237
for (int i = 0; i < wallArray.length; i++) {
238238
wallArray[i] = raw.walls(i);
239-
paintArray[i] = raw.paint(i);
239+
paintArray[i] = possiblyReversePaint(raw.paint(i), teamsReversed);
240240
}
241241
for (int i = 0; i < patternArray.length; i++){
242242
patternArray[i] = raw.paintPatterns(i);
@@ -294,6 +294,7 @@ public static int serialize(FlatBufferBuilder builder, LiveMap gameMap) {
294294
bodyTypes.add(FlatHelpers.getRobotTypeFromUnitType(robot.type));
295295
bodyLocsXs.add(robot.location.x);
296296
bodyLocsYs.add(robot.location.y);
297+
ruinArray[gameMap.locationToIndex(robot.location)] = true;
297298
}
298299

299300
for (int i = 0; i < gameMap.getWidth() * gameMap.getHeight(); i++) {
@@ -365,6 +366,19 @@ private static void initInitialBodiesFromSchemaBodyTable(InitialBodyTable bodyTa
365366
}
366367
}
367368

369+
// No color = 0, Team A color 1 = 1, Team A color 2 = 2, Team B color 1 = 3, Team B color 2 = 4
370+
private static byte possiblyReversePaint(byte originalPaint, boolean teamsReversed){
371+
if (!teamsReversed)
372+
return originalPaint;
373+
switch (originalPaint){
374+
case 1: return 3;
375+
case 2: return 4;
376+
case 3: return 1;
377+
case 4: return 2;
378+
default: return originalPaint;
379+
}
380+
}
381+
368382
private static int createSpawnActionsVector(FlatBufferBuilder builder, ArrayList<Integer> ids, ArrayList<Integer> xs, ArrayList<Integer> ys, ArrayList<Byte> teams, ArrayList<Byte> types){
369383
InitialBodyTable.startSpawnActionsVector(builder, ids.size());
370384
for (int i = 0; i < ids.size(); i++){

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,23 @@ public int getTowerPattern(UnitType towerType) {
577577
}
578578

579579
public boolean isValidPatternCenter(MapLocation loc) {
580-
return !(loc.x < GameConstants.PATTERN_SIZE / 2
580+
return (!(loc.x < GameConstants.PATTERN_SIZE / 2
581581
|| loc.y < GameConstants.PATTERN_SIZE / 2
582582
|| loc.x >= gameMap.getWidth() - (GameConstants.PATTERN_SIZE - 1) / 2
583583
|| loc.y >= gameMap.getHeight() - (GameConstants.PATTERN_SIZE - 1) / 2
584-
);
584+
)) && areaIsPaintable(loc) ;
585+
}
586+
587+
// checks that location has no walls/ruins in the surrounding 5x5 area
588+
public boolean areaIsPaintable(MapLocation loc){
589+
for (int dx = -GameConstants.PATTERN_SIZE / 2; dx < (GameConstants.PATTERN_SIZE + 1) / 2; dx++) {
590+
for (int dy = -GameConstants.PATTERN_SIZE / 2; dy < (GameConstants.PATTERN_SIZE + 1) / 2; dy++) {
591+
MapLocation newLoc = loc.translate(dx, dy);
592+
if (!isPaintable(newLoc))
593+
return false;
594+
}
595+
}
596+
return true;
585597
}
586598

587599
public boolean isPassable(MapLocation loc) {

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,20 @@ public void markResourcePattern(MapLocation loc, int rotationAngle, boolean refl
713713
this.gameWorld.markResourcePattern(getTeam(), loc, rotationAngle, reflect);
714714
}
715715

716+
private UnitType getBaseUnitType(UnitType type){
717+
UnitType baseType;
718+
switch (type){
719+
case LEVEL_TWO_DEFENSE_TOWER: baseType = UnitType.LEVEL_ONE_DEFENSE_TOWER; break;
720+
case LEVEL_THREE_DEFENSE_TOWER: baseType = UnitType.LEVEL_ONE_DEFENSE_TOWER; break;
721+
case LEVEL_TWO_MONEY_TOWER: baseType = UnitType.LEVEL_ONE_MONEY_TOWER; break;
722+
case LEVEL_THREE_MONEY_TOWER: baseType = UnitType.LEVEL_ONE_MONEY_TOWER; break;
723+
case LEVEL_TWO_PAINT_TOWER: baseType = UnitType.LEVEL_ONE_PAINT_TOWER; break;
724+
case LEVEL_THREE_PAINT_TOWER: baseType = UnitType.LEVEL_ONE_PAINT_TOWER; break;
725+
default: baseType = type;
726+
}
727+
return baseType;
728+
}
729+
716730
private void assertCanCompleteTowerPattern(UnitType type, MapLocation loc) throws GameActionException {
717731
assertIsRobotType(this.robot.getType());
718732
assertIsTowerType(type);
@@ -730,6 +744,12 @@ private void assertCanCompleteTowerPattern(UnitType type, MapLocation loc) throw
730744
+ ") because the center is not a ruin");
731745
}
732746

747+
if (getMoney() < getBaseUnitType(type).moneyCost){
748+
throw new GameActionException(CANT_DO_THAT,
749+
"Cannot complete tower pattern centered at (" + loc.x + ", " + loc.y
750+
+ ") because the team does not have enough money!");
751+
}
752+
733753
if (!this.gameWorld.isValidPatternCenter(loc)) {
734754
throw new GameActionException(CANT_DO_THAT,
735755
"Cannot complete tower pattern centered at (" + loc.x + ", " + loc.y
@@ -773,6 +793,7 @@ public void completeTowerPattern(UnitType type, MapLocation loc) throws GameActi
773793
assertCanCompleteTowerPattern(type, loc);
774794
this.gameWorld.completeTowerPattern(getTeam(), type, loc);
775795
InternalRobot tower = this.gameWorld.getRobot(loc);
796+
this.gameWorld.getTeamInfo().addMoney(getTeam(), -getBaseUnitType(type).moneyCost);
776797
this.gameWorld.getMatchMaker().addSpawnAction(tower.getID(), loc, tower.getTeam(), type);
777798
this.gameWorld.getMatchMaker().addBuildAction(tower.getID());
778799
}

0 commit comments

Comments
 (0)