Skip to content

Commit 0f6c29b

Browse files
committed
expose custom bot movement and harvest probability
- setting bot-type to CUSTOM enables bot parameterization with robot-movement-probability, robot-harvest-probability, and robot-moves-per-second - always use toCurrencyString to format currency
1 parent d23784f commit 0f6c29b

File tree

9 files changed

+46
-21
lines changed

9 files changed

+46
-21
lines changed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package edu.asu.commons.foraging.bot;
22

33
public enum BotType {
4-
AGGRESSIVE, COOPERATIVE, NORMAL, RANDOM;
5-
}
6-
4+
AGGRESSIVE, COOPERATIVE, NORMAL, RANDOM, CUSTOM;
5+
}

src/main/java/edu/asu/commons/foraging/bot/NormalBot.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ public class NormalBot extends Bot.SimpleBot {
1010

1111
public final static double MOVEMENT_PROBABILITY = 0.9d;
1212

13+
private BotType botType = BotType.NORMAL;
14+
1315
public NormalBot() {
1416
super(ACTIONS_PER_SECOND, MOVEMENT_PROBABILITY, HARVEST_PROBABILITY);
1517
}
1618

1719
public NormalBot(int actionsPerSecond, double movementProbability, double harvestProbability) {
1820
super(actionsPerSecond, movementProbability, harvestProbability);
21+
botType = BotType.CUSTOM;
1922
}
2023

2124
@Override
2225
public BotType getBotType() {
23-
return BotType.NORMAL;
26+
return botType;
2427
}
2528

2629
}

src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public boolean isLabDollarsEnabled() {
399399

400400
public String toCurrencyString(double amount) {
401401
if (isLabDollarsEnabled()) {
402-
return String.format("%d lab dollars", amount);
402+
return String.format("%s lab dollars", amount);
403403
}
404404
NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
405405
return currencyFormat.format(amount) + " " + currencyFormat.getCurrency().getCurrencyCode();
@@ -897,29 +897,27 @@ public String getClientDebriefing() {
897897

898898
public String generateClientDebriefing(ClientData data, boolean showExitInstructions) {
899899
ST st = createStringTemplate(getClientDebriefing());
900-
NumberFormat formatter = NumberFormat.getCurrencyInstance();
901-
populateClientEarnings(data, getParentConfiguration(), formatter, showExitInstructions);
900+
populateClientEarnings(data, getParentConfiguration(), isTrustGameEnabled());
902901
st.add("clientData", data);
903902
// FIXME: replace showExitInstructions within client debriefing with a ExitInstructions template?
904903
st.add("showExitInstructions", showExitInstructions);
905-
st.add("showUpPayment", formatter.format(getParentConfiguration().getShowUpPayment()));
904+
st.add("showUpPayment", toCurrencyString(getParentConfiguration().getShowUpPayment()));
906905
return st.render();
907906
}
908907

909-
private void populateClientEarnings(ClientData data, ServerConfiguration serverConfiguration, NumberFormat formatter, boolean includeTrustGame) {
910-
data.setGrandTotalIncome(formatter.format(serverConfiguration.getTotalIncome(data, includeTrustGame)));
911-
data.setCurrentIncome(formatter.format(tokensToDollars(data.getCurrentTokens())));
912-
data.setQuizEarnings(formatter.format(serverConfiguration.getQuizEarnings(data)));
913-
data.setTrustGameEarnings(formatter.format(data.getTrustGameIncome()));
908+
private void populateClientEarnings(ClientData data, ServerConfiguration serverConfiguration, boolean includeTrustGame) {
909+
data.setGrandTotalIncome(toCurrencyString(serverConfiguration.getTotalIncome(data, includeTrustGame)));
910+
data.setCurrentIncome(toCurrencyString(tokensToDollars(data.getCurrentTokens())));
911+
data.setQuizEarnings(toCurrencyString(serverConfiguration.getQuizEarnings(data)));
912+
data.setTrustGameEarnings(toCurrencyString(data.getTrustGameIncome()));
914913
}
915914

916915
public String generateFacilitatorDebriefing(ServerDataModel serverDataModel) {
917916
ST template = createStringTemplate(getFacilitatorDebriefingTemplate());
918917
template.add("lastRound", serverDataModel.isLastRound());
919918
ServerConfiguration serverConfiguration = getParentConfiguration();
920-
NumberFormat formatter = NumberFormat.getCurrencyInstance();
921919
for (ClientData data : serverDataModel.getClientDataMap().values()) {
922-
populateClientEarnings(data, serverConfiguration, formatter, true);
920+
populateClientEarnings(data, serverConfiguration, true);
923921
}
924922
template.add("clientDataList", serverDataModel.getClientDataMap().values());
925923
return template.render();
@@ -1003,7 +1001,11 @@ public int getRobotMovesPerSecond() {
10031001
* making a move
10041002
*/
10051003
public double getRobotHarvestProbability() {
1006-
return getDoubleProperty("robot-harvest-probability", 0.5d);
1004+
return getDoubleProperty("robot-harvest-probability", getParentConfiguration().getRobotHarvestProbability());
1005+
}
1006+
1007+
public double getRobotMovementProbability() {
1008+
return getDoubleProperty("robot-movement-probability", getParentConfiguration().getRobotMovementProbability());
10071009
}
10081010

10091011
public String getTokenImagePath() {

src/main/java/edu/asu/commons/foraging/conf/ServerConfiguration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,11 @@ public int getMaximumOccupancyPerCell() {
256256
return getIntProperty("max-cell-occupancy", 1);
257257
}
258258

259+
public double getRobotHarvestProbability() {
260+
return getDoubleProperty("robot-harvest-probability", 0.6d);
261+
}
262+
263+
public double getRobotMovementProbability() {
264+
return getDoubleProperty("robot-movement-probability", 0.9d);
265+
}
259266
}

src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,10 +924,23 @@ public void setImposedStrategy(Strategy imposedStrategy) {
924924

925925
public void addBots(int botsPerGroup, BotType botType) {
926926
int size = clients.size();
927+
RoundConfiguration configuration = getRoundConfiguration();
928+
double movementProbability = configuration.getRobotMovementProbability();
929+
double harvestProbability = configuration.getRobotHarvestProbability();
930+
int actionsPerSecond = configuration.getRobotMovesPerSecond();
927931
synchronized (bots) {
928932
bots.clear();
933+
929934
for (int i = 0; i < botsPerGroup; i++) {
930-
Bot bot = BotFactory.getInstance().create(botType, size + i + 1, this);
935+
int botNumber = size + i + 1;
936+
Bot bot = null;
937+
switch (botType) {
938+
case CUSTOM:
939+
bot = BotFactory.getInstance().create(botNumber, this, actionsPerSecond, movementProbability, harvestProbability);
940+
break;
941+
default:
942+
bot = BotFactory.getInstance().create(botType, size + i + 1, this);
943+
}
931944
bot.initialize(serverDataModel.getRoundConfiguration());
932945
bots.add(bot);
933946
}

src/main/resources/configuration/asu/2016/fmri.pretest/round1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<entry key='clients-per-group'>2</entry>
88
<entry key="resource-depth">9</entry>
99
<entry key="resource-width">9</entry>
10-
<entry key='bot-type'>COOPERATIVE</entry>
1110
<entry key='regrowth-rate'>0.05</entry>
11+
<entry key='robot-harvest-probability'>0.4</entry>
1212
<entry key='repeat'>5</entry>
1313
<entry key="instructions">
1414
<![CDATA[

src/main/resources/configuration/asu/2016/fmri.pretest/round2.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<entry key='clients-per-group'>2</entry>
88
<entry key="resource-depth">9</entry>
99
<entry key="resource-width">9</entry>
10-
<entry key='bot-type'>NORMAL</entry>
10+
<entry key='robot-harvest-probability'>0.7</entry>
1111
<entry key='regrowth-rate'>0.1</entry>
1212
<entry key='repeat'>5</entry>
1313
<entry key="instructions">

src/main/resources/configuration/asu/2016/fmri.pretest/round3.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<entry key='clients-per-group'>2</entry>
88
<entry key="resource-depth">9</entry>
99
<entry key="resource-width">9</entry>
10-
<entry key='bot-type'>AGGRESSIVE</entry>
10+
<entry key='robot-harvest-probability'>1.0</entry>
1111
<entry key='regrowth-rate'>0.15</entry>
1212
<entry key='repeat'>5</entry>
1313
<entry key="instructions">

src/main/resources/configuration/asu/2016/fmri.pretest/server.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<entry key="default-round-duration">40</entry>
1818
<entry key="use-background-texture">false</entry>
1919
<entry key='use-lab-dollars'>true</entry>
20+
<entry key='bot-type'>CUSTOM</entry>
2021
<entry key="use-token-image">true</entry>
2122
<entry key='token-image-path'>images/green-diamond.png</entry>
2223
<entry key="use-avatar-image">false</entry>
@@ -65,7 +66,7 @@ Please <b>wait quietly</b> and <b>do not close this window, open any other appli
6566
You will appear on the screen as a blue circle <img width='25' height='25' src="@CODEBASE_URL@/images/blue-circle.png"></img>.
6667
You can move by pressing the four arrow keys on your keyboard to move up, down, left, or right. You must press a key
6768
for each and every move. As you move around you can collect tokens
68-
<img width='25' height='25' src="@CODEBASE_URL@/images/green-diamond.png"></img> and earn <b>{dollarsPerToken} lab dollars</b>
69+
<img width='25' height='25' src="@CODEBASE_URL@/images/green-diamond.png"></img> and earn <b>{dollarsPerToken}</b>
6970
for each collected token. To collect a token, move your avatar over it and <b>press the space bar</b>. Simply moving
7071
your avatar over a token does <b>not collect</b> that token.
7172
</p>

0 commit comments

Comments
 (0)