Skip to content

Commit

Permalink
remove occupancy check and increase sync frequency
Browse files Browse the repository at this point in the history
- add explicit occupancy-enabled boolean parameter
- disable occupancy check in pretest configuration
- increase full synchronization frequency from 1 full sync every 10
  seconds to 1 full sync every 4 seconds. This may reduce performance a
  bit but should be neglible for single player
  • Loading branch information
alee committed Jan 31, 2017
1 parent df79363 commit 0c74f97
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void clear() {
public void initialize(GroupDataModel groupDataModel) {
clear();
singlePlayer = getRoundConfiguration().isSinglePlayer();
shouldCheckOccupancy = getRoundConfiguration().shouldCheckOccupancy();
shouldCheckOccupancy = getRoundConfiguration().isOccupancyEnabled();
maximumOccupancyPerCell = getRoundConfiguration().getMaximumOccupancyPerCell();
Map<Identifier, ClientData> clientDataMap = groupDataModel.getClientDataMap();
Identifier[] ids = new Identifier[clientDataMap.size()];
Expand Down Expand Up @@ -342,7 +342,7 @@ public int getClientZone(Identifier id) {
}

/**
* Only used in single player mode.
* Only used in single player mode.
*/
public void moveClient(Direction direction) {
synchronized (clientPositions) {
Expand All @@ -357,6 +357,7 @@ public void moveClient(Direction direction) {
public boolean isCellAvailable(Point position) {
if (shouldCheckOccupancy) {
int currentOccupancy = 0;
// FIXME: duplicated in GroupDataModel.isCellAvailable
for (Point otherPosition : getClientPositions().values()) {
if (position.equals(otherPosition)) {
currentOccupancy++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,8 @@ public boolean isSanctioningAllowed(int zoneA, int zoneB) {
return getBooleanProperty("sanction-allowed-" + zoneA + "-" + zoneB, true);
}

public boolean shouldCheckOccupancy() {
return (getMaximumOccupancyPerCell() < getClientsPerGroup())
|| (isSinglePlayer() && getMaximumOccupancyPerCell() > 0);
public boolean isOccupancyEnabled() {
return getBooleanProperty("occupancy-enabled", getParentConfiguration().isOccupancyEnabled());
}

public int getMaximumOccupancyPerCell() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ public int getMaximumOccupancyPerCell() {
return getIntProperty("max-cell-occupancy", 1);
}

public boolean isOccupancyEnabled() {
return getBooleanProperty("occupancy-enabled", true);
}

public double getRobotHarvestProbability() {
return getDoubleProperty("robot-harvest-probability", 0.6d);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import edu.asu.commons.net.Identifier;

/**
* $Id$
*
* Represents a collection of Clients and associates them with a token distribution. In the
* case of a shared resource model where all clients share the same world space, there will
Expand Down Expand Up @@ -518,7 +517,7 @@ public void moveClient(Identifier id, Direction direction) {

public boolean isCellAvailable(Point position) {
RoundConfiguration currentRoundConfiguration = getRoundConfiguration();
if (currentRoundConfiguration.shouldCheckOccupancy()) {
if (currentRoundConfiguration.isOccupancyEnabled()) {
int maximumOccupancyPerCell = currentRoundConfiguration.getMaximumOccupancyPerCell();
int currentOccupancy = 0;
for (Point otherPosition : getClientPositions().values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ private class ForagingStateMachine implements StateMachine {
private ResourceDispenser resourceDispenser;
private ServerState serverState;
private final Duration secondTick = Duration.create(1000L);
// bots tick every 100 ms
private final Duration botTick = Duration.create(100L);
private volatile boolean groupsInitialized;

Expand Down Expand Up @@ -952,10 +953,10 @@ private void advanceToNextRound() {

private void processSinglePlayerRound() {
// generate resources every second
// resources added
secondTick.onTick((duration) -> {
resourceDispenser.generateResources();
if (duration.isModulo(10)) {
// for a second duration, isModulo(N) will return true every N seconds
if (duration.isModulo(4)) {
clients.forEach((id, data) -> {
transmit(new SynchronizeClientEvent(data, currentRoundDuration.getTimeLeft()));
synchronizedClients.add(id);
Expand All @@ -964,7 +965,8 @@ private void processSinglePlayerRound() {
});
// activate bots
botTick.onTick((duration) -> {
// only activate bots every 100 ms or so, otherwise they frontload all their actions.
// botTick duration runs every 100ms, so duration.isModulo(10) will return true every 1s to reset
// bot actions every second.
serverDataModel.getGroups().forEach((group) -> group.activateBots(duration.isModulo(10)));
});
// update client with bot positions and updated resource totals
Expand All @@ -990,7 +992,6 @@ private void processSinglePlayerRound() {
group.clearDiffLists();
}
// post-process cleanup of transient data structures on ClientData

}

private void processRound() {
Expand All @@ -1012,7 +1013,7 @@ private void processRound() {
if (botGroupsEnabled) {
botTick.onTick((duration) -> {
for (GroupDataModel group : serverDataModel.getGroups()) {
// only activate bots every 100 ms or so, otherwise they frontload all their actions.
// only activate bots every 100 ms, otherwise they frontload all their actions.
// and clear all bot action taken counters every 1 s
boolean resetBotActions = duration.isModulo(10);
group.activateBots(resetBotActions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<entry key="round3">round3.xml</entry>
<entry key='quiz-correct-answer-reward'>0.10</entry>
<entry key='clients-per-group'>2</entry>
<entry key='occupancy-enabled'>false</entry>
<entry key='bot-groups-enabled'>true</entry>
<entry key='bots-per-group'>1</entry>
<entry key="wait-for-participants">true</entry>
Expand Down

0 comments on commit 0c74f97

Please sign in to comment.