Search in sources :

Example 6 with AbstractPlayer

use of core.player.AbstractPlayer in project SimpleAsteroids by ljialin.

the class SimpleGridTest method runOnce.

public static double runOnce() {
    // make an agent to test
    StateObservation gridGame = new GridModel();
    System.out.println(gridGame.getGameScore());
    System.out.println(gridGame.copy().getGameScore());
    // System.exit(0);
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    AbstractPlayer player;
    controllers.singlePlayer.sampleOLMCTS.Agent olmcts = new controllers.singlePlayer.sampleOLMCTS.Agent(gridGame, timer);
    controllers.singlePlayer.discountOLMCTS.Agent discountOlmcts = new controllers.singlePlayer.discountOLMCTS.Agent(gridGame, timer);
    controllers.singlePlayer.nestedMC.Agent nestedMC = new controllers.singlePlayer.nestedMC.Agent(gridGame, timer);
    player = olmcts;
    // player = discountOlmcts;
    // for the following we can pass the Evolutionary algorithm to use
    int nResamples = 2;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    int nEvals = 2000;
    double kExplore = 10;
    int nNeighbours = 100;
    evoAlg = new NTupleBanditEA(kExplore, nNeighbours);
    evoAlg = new SlidingMeanEDA();
    // DefaultMutator.totalRandomChaosMutation = false;
    Agent.useShiftBuffer = true;
    Agent.SEQUENCE_LENGTH = 30;
    player = new Agent(gridGame, timer, evoAlg, nEvals);
    nestedMC.maxRolloutLength = 30;
    nestedMC.nestDepth = 3;
    // player = nestedMC;
    // in milliseconds
    int thinkingTime = 50;
    int delay = 30;
    // player = new controllers.singlePlayer.sampleRandom.Agent(stateObs, timer);
    // check that we can play the game
    Random random = new Random();
    // this is how many steps we'll take in the actual game ...
    int nSteps = 30;
    ElapsedTimer t = new ElapsedTimer();
    for (int i = 0; i < nSteps && !gridGame.isGameOver(); i++) {
        timer = new ElapsedCpuTimer();
        timer.setMaxTimeMillis(thinkingTime);
        Types.ACTIONS action = player.act(gridGame.copy(), timer);
        System.out.println();
        // + "\t " + action.ordinal());
        System.out.println("Selected: " + action);
        gridGame.advance(action);
        System.out.println("Game state: " + gridGame);
        System.out.println();
    }
    System.out.println(gridGame.getGameScore());
    return gridGame.getGameScore();
}
Also used : Agent(controllers.singlePlayer.ea.Agent) Types(ontology.Types) GridModel(rl.grid.GridModel) SlidingMeanEDA(ntuple.SlidingMeanEDA) NTupleBanditEA(ntuple.NTupleBanditEA) EvoAlg(evodef.EvoAlg) StateObservation(core.game.StateObservation) SimpleRMHC(ga.SimpleRMHC) Random(java.util.Random) AbstractPlayer(core.player.AbstractPlayer) ElapsedTimer(utilities.ElapsedTimer) ElapsedCpuTimer(tools.ElapsedCpuTimer)

Aggregations

AbstractPlayer (core.player.AbstractPlayer)6 Types (ontology.Types)6 ElapsedCpuTimer (tools.ElapsedCpuTimer)6 ElapsedTimer (utilities.ElapsedTimer)5 Agent (controllers.singlePlayer.ea.Agent)4 EvoAlg (evodef.EvoAlg)4 SimpleRMHC (ga.SimpleRMHC)4 Random (java.util.Random)4 StateObservation (core.game.StateObservation)3 NTupleBanditEA (ntuple.NTupleBanditEA)3 JEasyFrame (utilities.JEasyFrame)3 SimpleMaxGame (altgame.SimpleMaxGame)2 View (asteroids.View)2 BattleView (battle.BattleView)1 SlidingMeanEDA (ntuple.SlidingMeanEDA)1 GridModel (rl.grid.GridModel)1