use of evodef.EvoAlg in project SimpleAsteroids by ljialin.
the class RandomTestPlanetWars method evaluate.
public static double evaluate(SimplePlayerInterface player) {
GameRunner gameRunner = new GameRunner();
EvoAlg evoAlgOpponent = new SimpleRMHC();
// set up some defaults for opponent
int nOpponentEvals = 400;
int opponentSeqLength = 5;
EvoAgent evoOpponent = new EvoAgent().setEvoAlg(evoAlgOpponent, nOpponentEvals).setSequenceLength(opponentSeqLength);
// setting to false provides a much weaker opponent
evoOpponent.setUseShiftBuffer(true);
// now run a game and return the result
gameRunner.verbose = false;
gameRunner.reset();
gameRunner.setPlayers(player, evoOpponent);
gameRunner.playGame();
double fitness = gameRunner.scores.mean();
double value = 0;
if (fitness > 0)
value = 1;
if (fitness < 0)
value = -1;
System.out.println("Fitness: " + (int) fitness + " : " + value);
System.out.println();
return value;
}
use of evodef.EvoAlg in project SimpleAsteroids by ljialin.
the class TwoPlayerTest method main.
public static void main(String[] args) throws Exception {
// AsteroidsGameState game = new AsteroidsGameState().setNPlanets(10).setRandomOwnerships().setRandomGrowthRates();
// .setNPlanets(10).setDOwnerships().setRandomGrowthRates();
GameState game = new GameState().defaultState();
GameState.includeBuffersInScore = true;
GameState.wrapAround = false;
PlanetWarView view = new PlanetWarView(game);
JEasyFrame frame = new JEasyFrame(view, "Test View");
KeyController controller = new KeyController();
frame.addKeyListener(controller);
int nResamples = 1;
EvoAlg evoAlg = new SimpleRMHC(nResamples);
int nEvals = 100;
int seqLength = 20;
// evoAlg = new SlidingMeanEDA().setHistoryLength(20);
System.out.println("Initial score: " + game.getScore());
EvoAgent evoAgent = new EvoAgent().setEvoAlg(evoAlg, nEvals).setSequenceLength(seqLength);
evoAgent.setUseShiftBuffer(true);
evoAgent.setVisual();
int delay = 2000;
GameActionSpaceAdapterMulti.visual = true;
Random random = new Random();
for (int i = 0; i < 500; i++) {
int p1, p2;
p1 = evoAgent.getAction(game, 0);
// p1 = random.nextInt(AsteroidsGameState.nActions);
p2 = controller.action(game);
// p2 = AsteroidsGameState.doNothing;
int[] a = new int[] { p1, p2 };
game.next(a);
// game.update();
view.update(game);
Thread.sleep(delay);
}
}
use of evodef.EvoAlg in project SimpleAsteroids by ljialin.
the class AgentOptTest method main.
// this is just a placeholder for the moment
// the idea is within this package to include
// some very clean and simple examples of how
// to set up GVGAI agents ready for optimisation
public static void main(String[] args) {
EvoAlg evoAlg = new CompactSlidingGA();
evoAlg = new NTupleBanditEA();
// evoAlg = new SlidingMeanEDA();
StatSummary ss = new StatSummary("Overall results: " + evoAlg.getClass().getSimpleName());
int nTrials = 1;
for (int i = 0; i < nTrials; i++) {
ss.add(runTrial(evoAlg));
}
System.out.println(ss);
}
Aggregations