Search in sources :

Example 21 with EvoAlg

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;
}
Also used : SimpleRMHC(ga.SimpleRMHC) EvoAlg(evodef.EvoAlg)

Example 22 with EvoAlg

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);
    }
}
Also used : JEasyFrame(utilities.JEasyFrame) SimpleRMHC(ga.SimpleRMHC) Random(java.util.Random) EvoAlg(evodef.EvoAlg)

Example 23 with EvoAlg

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);
}
Also used : StatSummary(utilities.StatSummary) CompactSlidingGA(ntuple.CompactSlidingGA) NTupleBanditEA(ntuple.NTupleBanditEA) EvoAlg(evodef.EvoAlg)

Aggregations

EvoAlg (evodef.EvoAlg)23 SimpleRMHC (ga.SimpleRMHC)17 Random (java.util.Random)9 NTupleBanditEA (ntuple.NTupleBanditEA)9 ElapsedCpuTimer (tools.ElapsedCpuTimer)9 Types (ontology.Types)7 ElapsedTimer (utilities.ElapsedTimer)7 SlidingMeanEDA (ntuple.SlidingMeanEDA)6 AbstractMultiPlayer (core.player.AbstractMultiPlayer)5 JEasyFrame (utilities.JEasyFrame)5 Agent (controllers.singlePlayer.ea.Agent)4 AbstractPlayer (core.player.AbstractPlayer)4 StatSummary (utilities.StatSummary)4 StateObservation (core.game.StateObservation)3 SimpleMaxGame (altgame.SimpleMaxGame)2 BattleView (battle.BattleView)2 Agent (controllers.multiPlayer.ea.Agent)2 StateObservationMulti (core.game.StateObservationMulti)2 AnnotatedFitnessSpace (evodef.AnnotatedFitnessSpace)2 CompactSlidingGA (ntuple.CompactSlidingGA)2