Skip to content

Commit 596bb14

Browse files
committed
add balance changes
1 parent 53e8cab commit 596bb14

5 files changed

Lines changed: 43 additions & 15 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public class GameConstants {
6161
/** The amount of cheese each team starts with. */
6262
public static final int INITIAL_TEAM_CHEESE = 2500;
6363

64+
/** The number of rounds after a backstab after which cat traps are disabled. */
65+
public static final int CAT_TRAP_ROUNDS_AFTER_BACKSTAB = 100;
66+
6467
/** The maximum number of rat kings that a team can have. */
6568
public static final int MAX_NUMBER_OF_RAT_KINGS = 5;
6669

@@ -219,7 +222,7 @@ public class GameConstants {
219222
public static final int DIG_DIRT_CHEESE_COST = 5;
220223

221224
/** The cheese cost to place a tile of dirt */
222-
public static final int PLACE_DIRT_CHEESE_COST = 3;
225+
public static final int PLACE_DIRT_CHEESE_COST = 0;
223226

224227

225228
// *********************************

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public enum UnitType {
44
// health, size, visionConeRadiusSquared, visionConeAngle, actionCooldown, movementCooldown, bytecodeLimit
55
BABY_RAT(100, 1, 20, 90, 10, 10, 17500),
6-
RAT_KING(500, 3, 25, 360, 10, 40, 20000),
6+
RAT_KING(600, 3, 25, 360, 10, 40, 20000),
77
CAT(4000, 2, 17, 180, 30, 20, 17500);
88

99
// amount of health robot initially starts with

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public class GameWorld {
2323
* Whether we're running.
2424
*/
2525
protected boolean running = true;
26-
protected boolean isCooperation = true;
26+
private boolean isCooperation = true;
27+
private int backstabRound = -1;
28+
private Team backstabber = null;
2729

2830
protected final IDGenerator idGenerator;
2931
protected final GameStats gameStats;
@@ -401,6 +403,25 @@ public boolean isCooperation() {
401403
return this.isCooperation;
402404
}
403405

406+
public int getRoundsSinceBackstab() {
407+
if (this.isCooperation) {
408+
return 0;
409+
} else {
410+
return this.currentRound - this.backstabRound;
411+
}
412+
}
413+
414+
public boolean catTrapsAllowed(Team team) {
415+
return this.isCooperation || (this.getRoundsSinceBackstab() <=
416+
GameConstants.CAT_TRAP_ROUNDS_AFTER_BACKSTAB && this.backstabber != team);
417+
}
418+
419+
public void backstab(Team backstabber) {
420+
this.isCooperation = false;
421+
this.backstabRound = this.currentRound;
422+
this.backstabber = backstabber;
423+
}
424+
404425
public boolean getWall(MapLocation loc) {
405426
return this.walls[locationToIndex(loc)];
406427
}
@@ -601,13 +622,14 @@ public void triggerTrap(Trap trap, InternalRobot robot) {
601622
TrapType type = trap.getType();
602623

603624
robot.setMovementCooldownTurns(type.stunTime);
625+
604626
if (type == TrapType.CAT_TRAP && robot.getType().isCatType()) {
605627
this.teamInfo.addDamageToCats(trap.getTeam(), Math.min(type.damage, robot.getHealth()));
606628
}
607629

608630
if (trap.getType() != TrapType.CAT_TRAP) {
609631
// initiate backstab
610-
this.isCooperation = false;
632+
backstab(robot.getTeam().opponent());
611633
}
612634

613635
matchMaker.addTrapTriggerAction(trap.getId(), loc, triggeringTeam, type);
@@ -807,7 +829,7 @@ public boolean setWinnerIfKilledAllRatKings() {
807829
* @return whether all cats dead
808830
*/
809831
public boolean setWinnerifAllCatsDead() {
810-
if (this.getNumCats() == 0 && this.isCooperation) { // only end game if no more cats in cooperation mode
832+
if (this.getNumCats() == 0 && this.isCooperation()) { // only end game if no more cats in cooperation mode
811833
// find out which team won via points
812834
if (setWinnerIfMorePoints())
813835
return true;
@@ -1134,7 +1156,7 @@ public void destroyRobot(int id, boolean fromException, boolean fromDamage) {
11341156
// check win
11351157
if (robot.getType() == UnitType.RAT_KING && this.getTeamInfo().getNumRatKings(robot.getTeam()) == 0) {
11361158
checkWin(robotTeam);
1137-
} else if (this.isCooperation && robot.getType() == UnitType.CAT && this.getNumCats() == 0) {
1159+
} else if (this.isCooperation() && robot.getType() == UnitType.CAT && this.getNumCats() == 0) {
11381160
checkWin(robotTeam);
11391161
}
11401162
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ public void bite(MapLocation loc, int cheeseConsumed) {
621621
targetRobot.addHealth(-damage);
622622

623623
if (targetRobot.getType() != UnitType.CAT) {
624-
this.gameWorld.isCooperation = false;
624+
this.gameWorld.backstab(this.team);
625625
}
626626
}
627627
}
@@ -646,7 +646,7 @@ public void grabRobot(MapLocation loc) {
646646
this.gameWorld.getMatchMaker().addRatNapAction(this.robotBeingCarried.getID());
647647

648648
if (this.robotBeingCarried.getTeam() != this.getTeam()) {
649-
this.gameWorld.isCooperation = false;
649+
this.gameWorld.backstab(this.getTeam());
650650
}
651651
}
652652

@@ -702,13 +702,13 @@ private void getGrabbed(InternalRobot grabber) {
702702
public void throwRobot() {
703703
this.gameWorld.getMatchMaker().endTurn(this.ID, this.health, this.cheeseAmount, this.movementCooldownTurns,
704704
this.actionCooldownTurns, this.turningCooldownTurns, this.bytecodesUsed, this.location, this.dir,
705-
this.gameWorld.isCooperation);
705+
this.gameWorld.isCooperation());
706706
this.robotBeingCarried.getThrown(this.dir);
707707
this.gameWorld.getMatchMaker().endTurn(this.robotBeingCarried.ID, this.robotBeingCarried.health,
708708
this.robotBeingCarried.cheeseAmount, this.robotBeingCarried.movementCooldownTurns,
709709
this.robotBeingCarried.actionCooldownTurns, this.robotBeingCarried.turningCooldownTurns,
710710
this.robotBeingCarried.bytecodesUsed, this.robotBeingCarried.location, this.robotBeingCarried.dir,
711-
this.gameWorld.isCooperation);
711+
this.gameWorld.isCooperation());
712712
this.gameWorld.addHasTraveledRobot(this.robotBeingCarried.getID());
713713
this.gameWorld.getMatchMaker().addThrowAction(this.robotBeingCarried.getID(),
714714
this.getLocation().add(this.dir));
@@ -1401,13 +1401,13 @@ public void processEndOfTurn() {
14011401

14021402
this.gameWorld.getMatchMaker().endTurn(this.ID, this.health, this.cheeseAmount, this.movementCooldownTurns,
14031403
this.actionCooldownTurns, this.turningCooldownTurns, this.bytecodesUsed, this.location, this.dir,
1404-
this.gameWorld.isCooperation);
1404+
this.gameWorld.isCooperation());
14051405
if (this.isCarryingRobot() && this.robotBeingCarried.getHealth() > 0)
14061406
this.gameWorld.getMatchMaker().endTurn(this.robotBeingCarried.ID, this.robotBeingCarried.health,
14071407
this.robotBeingCarried.cheeseAmount, this.robotBeingCarried.movementCooldownTurns,
14081408
this.robotBeingCarried.actionCooldownTurns, this.robotBeingCarried.turningCooldownTurns,
14091409
this.robotBeingCarried.bytecodesUsed, this.location, this.robotBeingCarried.dir,
1410-
this.gameWorld.isCooperation);
1410+
this.gameWorld.isCooperation());
14111411
this.roundsAlive++;
14121412
}
14131413

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public int getMapHeight() {
103103

104104
@Override
105105
public boolean isCooperation() {
106-
return this.gameWorld.isCooperation;
106+
return this.gameWorld.isCooperation();
107107
}
108108

109109
// *********************************
@@ -329,8 +329,8 @@ private void assertCanPlaceTrap(MapLocation loc, TrapType trapType) throws GameA
329329
? GameConstants.RAT_KING_BUILD_DISTANCE_SQUARED
330330
: GameConstants.BUILD_DISTANCE_SQUARED);
331331

332-
if (trapType == TrapType.CAT_TRAP && !this.gameWorld.isCooperation)
333-
throw new GameActionException(CANT_DO_THAT, "Can't place new cat traps in backstabbing mode!");
332+
if (trapType == TrapType.CAT_TRAP && !this.gameWorld.catTrapsAllowed(this.getTeam()))
333+
throw new GameActionException(CANT_DO_THAT, "Can't place new cat traps in backstabbing mode after " + GameConstants.CAT_TRAP_ROUNDS_AFTER_BACKSTAB + " rounds!");
334334
if (!this.gameWorld.isPassable(loc))
335335
throw new GameActionException(CANT_DO_THAT, "Can't place trap on a wall or dirt!");
336336
if (this.gameWorld.getRobot(loc) != null)
@@ -1203,11 +1203,14 @@ public boolean canBecomeRatKing() {
12031203
public void becomeRatKing() throws GameActionException {
12041204
assertCanBecomeRatKing();
12051205
int health = 0;
1206+
12061207
for (Direction d : Direction.allDirections()) {
12071208
InternalRobot currentRobot = this.gameWorld.getRobot(this.adjacentLocation(d));
1209+
12081210
if (currentRobot != null && robot.getTeam() == currentRobot.getTeam()) {
12091211
health += currentRobot.getHealth();
12101212
}
1213+
12111214
if (currentRobot != null && d != Direction.CENTER) {
12121215
// all their raw cheese is taken
12131216
this.gameWorld.getTeamInfo().addCheese(this.getTeam(), currentRobot.getCheese());

0 commit comments

Comments
 (0)