Skip to content

Commit

Permalink
Merge pull request #30 from battlecode/engine-fixes
Browse files Browse the repository at this point in the history
report resource drops and resource changes to client
  • Loading branch information
wflms20110333 authored Jan 1, 2022
2 parents fa1d1fd + c4f4034 commit 33a4878
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
11 changes: 9 additions & 2 deletions engine/src/main/battlecode/world/GameWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ public void processEndOfRound() {
if (anomaly == AnomalyType.VORTEX) causeVortexGlobal();
}

this.matchMaker.addTeamInfo(Team.A, this.teamInfo.getRoundLeadChange(Team.A), this.teamInfo.getRoundGoldChange(Team.A));
this.matchMaker.addTeamInfo(Team.B, this.teamInfo.getRoundLeadChange(Team.B), this.teamInfo.getRoundGoldChange(Team.B));
this.teamInfo.processEndOfRound();

// Check for end of match
if (timeLimitReached() && gameStats.getWinner() == null)
if (!setWinnerIfMoreArchons())
Expand Down Expand Up @@ -468,13 +472,16 @@ public void destroyRobot(int id) {
RobotType type = robot.getType();
Team team = robot.getTeam();
removeRobot(robot.getLocation());

int leadDropped = robot.getType().getLeadDropped(robot.getLevel());
int goldDropped = robot.getType().getGoldDropped(robot.getLevel());

this.lead[locationToIndex(robot.getLocation())] += leadDropped;
this.gold[locationToIndex(robot.getLocation())] += goldDropped;

this.matchMaker.addLeadDrop(robot.getLocation(), leadDropped);
this.matchMaker.addLeadDrop(robot.getLocation(), goldDropped);

controlProvider.robotKilled(robot);
objectInfo.destroyRobot(id);

Expand Down
21 changes: 21 additions & 0 deletions engine/src/main/battlecode/world/TeamInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class TeamInfo {
private int[] goldCounts;
private int[][] sharedArrays;

// for reporting round statistics to client
private int[] oldLeadCounts;
private int[] oldGoldCounts;

/**
* Create a new representation of TeamInfo
*
Expand All @@ -26,6 +30,8 @@ public TeamInfo(GameWorld gameWorld) {
this.leadCounts = new int[2];
this.goldCounts = new int[2];
this.sharedArrays = new int[2][GameConstants.SHARED_ARRAY_LENGTH];
this.oldLeadCounts = new int[2];
this.oldGoldCounts = new int[2];
}

// *********************************
Expand Down Expand Up @@ -105,4 +111,19 @@ public void addGold(Team team, int amount) throws IllegalArgumentException {
public void writeSharedArray(Team team, int index, int value) {
this.sharedArrays[team.ordinal()][index] = value;
}

public int getRoundLeadChange(Team team) {
return this.leadCounts[team.ordinal()] - this.oldLeadCounts[team.ordinal()];
}

public int getRoundGoldChange(Team team) {
return this.goldCounts[team.ordinal()] - this.oldGoldCounts[team.ordinal()];
}

public void processEndOfRound() {
this.oldLeadCounts[0] = this.leadCounts[0];
this.oldLeadCounts[1] = this.leadCounts[1];
this.oldGoldCounts[0] = this.goldCounts[0];
this.oldGoldCounts[1] = this.goldCounts[1];
}
}

0 comments on commit 33a4878

Please sign in to comment.