Search in sources :

Example 1 with GridModel

use of rl.grid.GridModel 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

Agent (controllers.singlePlayer.ea.Agent)1 StateObservation (core.game.StateObservation)1 AbstractPlayer (core.player.AbstractPlayer)1 EvoAlg (evodef.EvoAlg)1 SimpleRMHC (ga.SimpleRMHC)1 Random (java.util.Random)1 NTupleBanditEA (ntuple.NTupleBanditEA)1 SlidingMeanEDA (ntuple.SlidingMeanEDA)1 Types (ontology.Types)1 GridModel (rl.grid.GridModel)1 ElapsedCpuTimer (tools.ElapsedCpuTimer)1 ElapsedTimer (utilities.ElapsedTimer)1