Skip to content

Commit

Permalink
switch to 500ms resolution and add Bot.NULL object
Browse files Browse the repository at this point in the history
- change "velocity" to only count number of moves, and rename for
clarity
- closes #19
  • Loading branch information
alee committed Sep 11, 2017
1 parent 66eff2f commit 318795f
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 37 deletions.
126 changes: 108 additions & 18 deletions src/main/java/edu/asu/commons/foraging/bot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,129 @@ public interface Bot extends Actor {
*
* FIXME: consider injecting the model / state of the world for the bot as a parameter
*/
public void act();
void act();

public BotType getBotType();
BotType getBotType();

public Identifier getId();
Identifier getId();

public Point getPosition();
Point getPosition();

public int getCurrentTokens();
int getCurrentTokens();

public void addToken(Point location);
void addToken(Point location);

public void setCurrentPosition(Point location);
void setCurrentPosition(Point location);

public int getActionsPerSecond();
int getActionsPerSecond();

public void resetActionsTakenPerSecond();
void resetActionsTakenPerSecond();

public double getMovementProbability();
double getMovementProbability();

public Direction getNextMove();
Direction getNextMove();

public void initialize(RoundConfiguration configuration);
void initialize(RoundConfiguration configuration);

public int getTicksToWait();
int getTicksToWait();

public void setTicksToWait(int ticksToWait);
void setTicksToWait(int ticksToWait);

public int getBotNumber();
int getBotNumber();

public void setBotNumber(int botNumber);
void setBotNumber(int botNumber);

public void setGroupDataModel(GroupDataModel model);
void setGroupDataModel(GroupDataModel model);

public final static Bot NULL = new Bot() {

@Override
public void act() {
}

@Override
public BotType getBotType() {
return null;
}

@Override
public Identifier getId() {
return Identifier.NULL;
}

@Override
public Point getPosition() {
return new Point(-1, -1);
}

@Override
public GroupDataModel getGroupDataModel() {
return null;
}

@Override
public int getCurrentTokens() {
return 0;
}

@Override
public void addToken(Point location) {
}

@Override
public void setCurrentPosition(Point location) {
}

@Override
public int getActionsPerSecond() {
return 0;
}

@Override
public void resetActionsTakenPerSecond() {

}

@Override
public double getMovementProbability() {
return 0;
}

@Override
public Direction getNextMove() {
return Direction.NONE;
}

@Override
public void initialize(RoundConfiguration configuration) {

}

@Override
public int getTicksToWait() {
return 0;
}

@Override
public void setTicksToWait(int ticksToWait) {

}

@Override
public int getBotNumber() {
return -1;
}

@Override
public void setBotNumber(int botNumber) {

}

@Override
public void setGroupDataModel(GroupDataModel model) {

}
};

/**
* Provides simple default bot state and behavior.
Expand All @@ -65,7 +155,7 @@ public interface Bot extends Actor {
* or harvest a token if they are currently on top of a token.
* 4. randomized behavior if harvest probability fails or movement is unsuccessful (due to player blockage).
*/
public abstract class SimpleBot implements Bot, Serializable {
abstract class SimpleBot implements Bot, Serializable {

private static final long serialVersionUID = 2437093153712520070L;
public final static int DEFAULT_ACTIONS_PER_SECOND = 8;
Expand Down
34 changes: 15 additions & 19 deletions src/main/java/edu/asu/commons/foraging/data/BotDataProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class BotDataProcessor extends SaveFileProcessor.Base {
private Logger logger = Logger.getLogger(getClass().getName());

public BotDataProcessor() {
setSecondsPerInterval(1);
super(500);
}

@Override
Expand All @@ -35,20 +35,19 @@ public void process(SavedRoundData savedRoundData, PrintWriter writer) {
ServerDataModel dataModel = (ServerDataModel) savedRoundData.getDataModel();
dataModel.reinitialize(roundConfiguration);
// generate summarized statistics
// Time (100-200ms resolution), Subject Number, X, Y, Number of tokens collected, Distance to bot, current velocity
// Time (500ms resolution), Subject Number, X, Y, Number of tokens collected, Distance to bot, number of moves
// see https://github.com/virtualcommons/foraging/issues/19
writer.println(
Utils.join(',', "Time", "Subject ID", "X", "Y", "Tokens collected", "Velocity",
"Distance to bot", "Bot X", "Bot Y", "Bot Tokens", "Bot velocity")
Utils.join(',', "Time", "Subject ID", "X", "Y", "Tokens collected", "Player moves",
"Distance to bot", "Bot X", "Bot Y", "Bot Tokens", "Bot moves")
);
Map<Identifier, Actor> actorMap = dataModel.getActorMap();
Map<Identifier, ClientMovementTokenCount> clientMovement = ClientMovementTokenCount.createMap(dataModel);
double distanceToBot = 0.0d;
int actionsTaken = 0;
int botActionsTaken = 0;
assert actorMap.size() == 2;
ClientData client = null;
Bot bot = null;
Bot bot = Bot.NULL;
for (Actor actor: actorMap.values()) {
if (actor instanceof Bot) {
bot = (Bot) actor;
Expand All @@ -58,18 +57,17 @@ else if (actor instanceof ClientData) {
client = (ClientData) actor;
}
}
logger.info("XXX: bot map: " + actorMap);
for (PersistableEvent event: savedRoundData.getActions()) {
long secondsElapsed = savedRoundData.getElapsedTimeInSeconds(event);
long millisecondsElapsed = savedRoundData.getElapsedTime(event);
logger.info("Inspecting event: " + event);
if (isIntervalElapsed(secondsElapsed)) {
if (isIntervalElapsed(millisecondsElapsed)) {
// write out aggregated stats
Point clientPosition = client.getPosition();
Point botPosition = bot.getPosition();
distanceToBot = clientPosition.distanceSq(botPosition);
double distanceToBot = clientPosition.distance(botPosition);
writer.println(
Utils.join(',',
secondsElapsed,
getIntervalEnd(),
client.getId().getStationId(),
clientPosition.x,
clientPosition.y,
Expand All @@ -86,14 +84,12 @@ else if (actor instanceof ClientData) {
botActionsTaken = 0;
}
Identifier id = event.getId();
if (event instanceof TokenCollectedEvent) {

}
if (id instanceof BotIdentifier) {
botActionsTaken++;
}
else if (id instanceof SocketIdentifier) {
actionsTaken++;
if (event instanceof MovementEvent) {
if (id instanceof BotIdentifier) {
botActionsTaken++;
} else if (id instanceof SocketIdentifier) {
actionsTaken++;
}
}
dataModel.apply(event);
}
Expand Down

0 comments on commit 318795f

Please sign in to comment.