use of gvglink.SpaceBattleLinkState in project SimpleAsteroids by ljialin.
the class GameActionSpaceAdapter method evaluate.
@Override
public double evaluate(int[] actions) {
// take a copy of the current game state and accumulate the score as we go along
StateObservation obs = stateObservation.copy();
// note the score now - for normalisation reasons
// we wish to track the change in score, not the absolute score
double initScore = obs.getGameScore();
double discount = 1.0;
double denom = 0;
double discountedTot = 0;
// need to do the visual stuff here ...
LinePlot linePlot = null;
if (visual) {
float grey = (nEvals % 100) / 100;
linePlot = new LinePlot().setColor(new Color(grey, grey, grey));
}
for (int i = 0; i < sequenceLength; i++) {
obs.advance(gvgaiActions[actions[i]]);
discountedTot += discount * (obs.getGameScore() - initScore);
if (useHeuristic && obs instanceof SpaceBattleLinkState) {
SpaceBattleLinkState state = (SpaceBattleLinkState) obs;
discountedTot += state.getHeuristicScore();
}
denom += discount;
discount *= discountFactor;
if (linePlot != null) {
linePlot.add(discountedTot + Math.random() * 0);
}
}
if (visual) {
linePlots.add(linePlot);
}
nEvals++;
double delta;
if (useDiscountFactor) {
delta = discountedTot / denom;
} else {
delta = obs.getGameScore() - initScore;
}
delta += noiseLevel * random.nextGaussian();
logger.log(delta, actions, false);
return delta;
}
Aggregations