Skip to content

Commit

Permalink
Fix: add(other) wasn't working. Separated clear().
Browse files Browse the repository at this point in the history
  • Loading branch information
timhutton committed Jul 3, 2016
1 parent b46a439 commit a9c4c15
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ private void sendData() {
MultidimensionalReward reward = new MultidimensionalReward();
currentMissionBehaviour().rewardProducer.getReward(currentMissionInit(), reward);
if (!reward.isEmpty()) {
if (this.rewardSocket.sendTCPString(reward.getAsStringAndClear())) {
if (this.rewardSocket.sendTCPString(reward.getAsString())) {
this.failedTCPRewardSendCount = 0; // Reset the count of
// consecutive TCP
// failures.
Expand Down Expand Up @@ -1597,8 +1597,10 @@ protected void execute() {
// this
// manually.
missionEnded.setHumanReadableStatus(report);
if(!ClientStateMachine.this.finalReward.isEmpty())
missionEnded.setReward(ClientStateMachine.this.finalReward.getAndClear());
if(!ClientStateMachine.this.finalReward.isEmpty()) {
missionEnded.setReward(ClientStateMachine.this.finalReward.getAsReward());
ClientStateMachine.this.finalReward.clear();
}
// And send it to the agent to inform it that the mission has
// ended:
sendMissionEnded(missionEnded);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void add(int dimension, float value) {
if(this.map.containsKey(dimension))
this.map.put(dimension, this.map.get(dimension) + value);
else
this.map.put(dimension, value );
this.map.put(dimension, value);
}

/**
Expand All @@ -66,20 +66,19 @@ public void add(int dimension, float value) {
* the other multidimensional reward structure.
*/
public void add(MultidimensionalReward other) {
for (HashMap.Entry<Integer, Float> entry : this.map.entrySet()) {
for (HashMap.Entry<Integer, Float> entry : other.map.entrySet()) {
Integer dimension = entry.getKey();
Float reward_value = entry.getValue();
this.add(dimension.intValue(), reward_value.floatValue());
}
}

/**
* Retrieve the reward structure as defined by the schema, and reset the
* storage.
* Retrieve the reward structure as defined by the schema.
*
* @return the reward structure as defined by the schema.
*/
public Reward getAndClear() {
public Reward getAsReward() {
Reward reward = new Reward();
for (HashMap.Entry<Integer, Float> entry : this.map.entrySet()) {
Integer dimension = entry.getKey();
Expand All @@ -89,7 +88,6 @@ public Reward getAndClear() {
reward_entry.setValue(new BigDecimal(reward_value));
reward.getValue().add(reward_entry);
}
this.clear();
return reward;
}

Expand All @@ -98,11 +96,11 @@ public Reward getAndClear() {
*
* @return the XML string.
*/
public String getAsStringAndClear() {
public String getAsString() {
// Create a string XML representation:
String rewardString = null;
try {
rewardString = SchemaHelper.serialiseObject(this.getAndClear(), Reward.class);
rewardString = SchemaHelper.serialiseObject(this.getAsReward(), Reward.class);
} catch (JAXBException e) {
System.out.println("Caught reward serialization exception: " + e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ protected void addItemSpecToRewardStructure(ItemSpec is) {
protected void accumulateReward(int dimension, ItemStack stack) {
String item = stack.getItem().getUnlocalizedName();
Float f = this.rewardMap.get(item);
if (f != null)
if (f != null) {
this.accumulatedRewards.add(dimension, f * stack.stackSize);
}
}
}

0 comments on commit a9c4c15

Please sign in to comment.