Search in sources :

Example 6 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class GameTickTest method main.

public static void main(String[] args) {
    ElapsedTimer timer = new ElapsedTimer();
    int gameTickMillis = 40;
    int nTicks = 500;
    int nTrials = 10000;
    Random random = new Random();
    for (int i = 0; i < nTrials; i++) {
        StateObservationMulti game = new SpaceBattleLinkStateTwoPlayer();
        // SimpleBattleState game = new SimpleBattleState();
        controllers.multiPlayer.sampleRandom.Agent randomAgent = new controllers.multiPlayer.sampleRandom.Agent(game, null, 0);
        for (int j = 0; j < nTicks; j++) {
            Types.ACTIONS a1 = randomAgent.act(game, null);
            Types.ACTIONS a2 = randomAgent.act(game, null);
            Types.ACTIONS[] actions = new Types.ACTIONS[] { a1, a2 };
            game.advance(actions);
        // int[] actions = new int[]{random.nextInt(game.nActions()), random.nextInt(game.nActions())};
        // game.next(actions);
        }
    // System.out.println(i + "\t " + game.getGameTick());
    }
    int totalTicks = nTicks * nTrials;
    System.out.format("Made %d ticks\n", totalTicks);
    System.out.format("Ticks per milli-second: %.1f\n\n", totalTicks / (double) timer.elapsed());
    // System.out.format("Game tick time = %d ms\n", (int) gameTick);
    System.out.format("Updates per game tick:   %d\n\n", (int) (gameTickMillis * totalTicks / (double) timer.elapsed()));
    System.out.println(timer);
}
Also used : Types(ontology.Types) Random(java.util.Random) ElapsedTimer(utilities.ElapsedTimer) StateObservationMulti(core.game.StateObservationMulti) SpaceBattleLinkStateTwoPlayer(gvglink.SpaceBattleLinkStateTwoPlayer)

Example 7 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class PlanetWarsLinkTest method main.

// todo: show a graphic of the rollout predictions
// split this in to two parts
// for each action, we need to collect the data
// then we need to display the data
// each time plot the fitness of each sample versus the length
// of the rollout - this will give a good idea of what we need to plot...
// todo: implement a collision mechanism
// todo: implement a nice graphic that shows transfer from planet to buffer
// this is very easy to do - but question of whether we need a timed or instant movement...
public static void main(String[] args) throws Exception {
    int nTrials = 100;
    ElapsedTimer timer = new ElapsedTimer();
    StatSummary ss = new StatSummary();
    for (int i = 0; i < nTrials; i++) {
        System.out.println("Game: " + i);
        ss.add(runTest());
        System.out.println();
    }
    System.out.println(ss);
    System.out.println(timer);
}
Also used : StatSummary(utilities.StatSummary) ElapsedTimer(utilities.ElapsedTimer)

Example 8 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class SimpleMaxNTest method runOnce.

public static double runOnce() {
    // make an agent to test
    StateObservation noiseFree = new SimpleMaxGame();
    // new NoisyMaxGame();
    StateObservation stateObs = new SimpleMaxGame();
    System.out.println(stateObs.getGameScore());
    System.out.println(stateObs.copy().getGameScore());
    // System.exit(0);
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    AbstractPlayer player;
    controllers.singlePlayer.sampleOLMCTS.Agent olmcts = new controllers.singlePlayer.sampleOLMCTS.Agent(stateObs, timer);
    controllers.singlePlayer.discountOLMCTS.Agent discountOlmcts = new controllers.singlePlayer.discountOLMCTS.Agent(stateObs, timer);
    controllers.singlePlayer.nestedMC.Agent nestedMC = new controllers.singlePlayer.nestedMC.Agent(stateObs, 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 = 1000;
    double kExplore = 10;
    int nNeighbours = 100;
    evoAlg = new NTupleBanditEA(kExplore, nNeighbours);
    // DefaultMutator.totalRandomChaosMutation = true;
    Agent.useShiftBuffer = false;
    controllers.singlePlayer.ea.Agent.SEQUENCE_LENGTH = 100;
    player = new controllers.singlePlayer.ea.Agent(stateObs, timer, evoAlg, nEvals);
    nestedMC.maxRolloutLength = 5;
    nestedMC.nestDepth = 5;
    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 = 10;
    ElapsedTimer t = new ElapsedTimer();
    for (int i = 0; i < nSteps && !stateObs.isGameOver(); i++) {
        timer = new ElapsedCpuTimer();
        timer.setMaxTimeMillis(thinkingTime);
        Types.ACTIONS action = player.act(stateObs.copy(), timer);
        // System.out.println("Selected: " + action); //  + "\t " + action.ordinal());
        stateObs.advance(action);
        noiseFree.advance(action);
    // System.out.println(stateObs.getGameScore());
    }
    System.out.println(stateObs.getGameScore());
    System.out.println(noiseFree.getGameScore());
    System.out.println(stateObs.isGameOver());
    System.out.println(t);
    return noiseFree.getGameScore();
}
Also used : Agent(controllers.singlePlayer.ea.Agent) Types(ontology.Types) NTupleBanditEA(ntuple.NTupleBanditEA) Agent(controllers.singlePlayer.ea.Agent) EvoAlg(evodef.EvoAlg) StateObservation(core.game.StateObservation) SimpleRMHC(ga.SimpleRMHC) Random(java.util.Random) SimpleMaxGame(altgame.SimpleMaxGame) AbstractPlayer(core.player.AbstractPlayer) ElapsedTimer(utilities.ElapsedTimer) ElapsedCpuTimer(tools.ElapsedCpuTimer)

Example 9 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class SpaceBattleLinkTest method main.

public static void main(String[] args) {
    StatSummary ss = new StatSummary();
    int nTrials = 10;
    ElapsedTimer t = new ElapsedTimer();
    for (int i = 0; i < nTrials; i++) {
        System.out.println("Trial: " + i);
        ss.add(runTrial(runVisible));
        System.out.println();
    }
    System.out.println(ss);
    System.out.println();
    System.out.println(t);
}
Also used : StatSummary(utilities.StatSummary) ElapsedTimer(utilities.ElapsedTimer)

Example 10 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class SpaceBattleLinkTest method runTrial.

public static double runTrial(boolean runVisible) {
    // make an agent to test
    StateObservation stateObs = new SimpleMaxGame();
    // BattleGameSearchSpace.inject(BattleGameSearchSpace.getRandomPoint());
    // SampleEvolvedParams.solutions[1][2] = 5;
    // BattleGameSearchSpace.inject(SampleEvolvedParams.solutions[1]);
    // BattleGameSearchSpace.inject(SampleEvolvedParams.solutions[2]);
    BattleGameSearchSpace.inject(SampleEvolvedParams.solutions[1]);
    System.out.println("Params are:");
    System.out.println(BattleGameParameters.params);
    // can also overide parameters by setting them directly as follows:
    // BattleGameParameters.loss = 1.1;
    SpaceBattleLinkState linkState = new SpaceBattleLinkState();
    // set some parameters for the experiment
    GameActionSpaceAdapter.useHeuristic = false;
    Agent.useShiftBuffer = true;
    // DefaultMutator.totalRandomChaosMutation = false;
    // // supercl
    // StateObservation stateObs = linkState;
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    AbstractPlayer player;
    // controllers.singlePlayer.sampleOLMCTS.Agent olmcts =
    // new controllers.singlePlayer.sampleOLMCTS.Agent(linkState, timer);
    player = new controllers.singlePlayer.discountOLMCTS.Agent(linkState, timer);
    // try the evolutionary players
    int nResamples = 2;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    double kExplore = 10;
    int nNeighbours = 100;
    int nEvals = 200;
    evoAlg = new NTupleBanditEA(kExplore, nNeighbours);
    // player = new controllers.singlePlayer.ea.Agent(linkState, timer, evoAlg, nEvals);
    controllers.singlePlayer.nestedMC.Agent nestedMC = new controllers.singlePlayer.nestedMC.Agent(linkState, timer);
    nestedMC.maxRolloutLength = 10;
    nestedMC.nestDepth = 2;
    player = nestedMC;
    // in milliseconds
    int thinkingTime = 50;
    int delay = 10;
    // player = new controllers.singlePlayer.sampleRandom.Agent(stateObs, timer);
    // check that we can play the game
    Random random = new Random();
    int nSteps = 500;
    ElapsedTimer t = new ElapsedTimer();
    BattleView view = new BattleView(linkState.state);
    // set view to null to run fast with no visuals
    if (!runVisible)
        view = null;
    if (view != null) {
        new JEasyFrame(view, "Simple Battle Game");
    }
    boolean verbose = false;
    for (int i = 0; i < nSteps && !linkState.isGameOver(); i++) {
        ArrayList<Types.ACTIONS> actions = linkState.getAvailableActions();
        timer = new ElapsedCpuTimer();
        timer.setMaxTimeMillis(thinkingTime);
        Types.ACTIONS action = player.act(linkState.copy(), timer);
        // action = actions.get(random.nextInt(actions.size()));
        if (verbose)
            // + "\t " + action.ordinal());
            System.out.println(i + "\t Selected: " + action);
        linkState.advance(action);
        if (view != null) {
            view.repaint();
            try {
                Thread.sleep(delay);
            } catch (Exception e) {
            }
        }
        if (verbose)
            System.out.println(linkState.getGameScore());
    }
    System.out.println("Game score: " + linkState.getGameScore());
    return linkState.getGameScore();
}
Also used : Types(ontology.Types) NTupleBanditEA(ntuple.NTupleBanditEA) EvoAlg(evodef.EvoAlg) StateObservation(core.game.StateObservation) Random(java.util.Random) JEasyFrame(utilities.JEasyFrame) SimpleMaxGame(altgame.SimpleMaxGame) AbstractPlayer(core.player.AbstractPlayer) ElapsedTimer(utilities.ElapsedTimer) ElapsedCpuTimer(tools.ElapsedCpuTimer) Agent(controllers.singlePlayer.ea.Agent) BattleView(battle.BattleView) SimpleRMHC(ga.SimpleRMHC)

Aggregations

ElapsedTimer (utilities.ElapsedTimer)63 StatSummary (utilities.StatSummary)27 Random (java.util.Random)12 SimpleRMHC (ga.SimpleRMHC)9 Types (ontology.Types)9 ElapsedCpuTimer (tools.ElapsedCpuTimer)9 EvoAlg (evodef.EvoAlg)7 NTupleBanditEA (ntuple.NTupleBanditEA)7 JEasyFrame (utilities.JEasyFrame)7 ArrayList (java.util.ArrayList)6 AbstractPlayer (core.player.AbstractPlayer)5 Gson (com.google.gson.Gson)4 Agent (controllers.singlePlayer.ea.Agent)4 StateObservationMulti (core.game.StateObservationMulti)4 StateObservation (core.game.StateObservation)3 AbstractMultiPlayer (core.player.AbstractMultiPlayer)3 GameParameters (evogame.GameParameters)3 ConvNTuple (ntuple.ConvNTuple)3 SlidingMeanEDA (ntuple.SlidingMeanEDA)3 SimpleMaxGame (altgame.SimpleMaxGame)2