Search in sources :

Example 21 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class DiffGameSpeedTest method main.

public static void main(String[] args) {
    DiffGame dg = new DiffGame();
    ElapsedTimer t = new ElapsedTimer();
    Types.ACTIONS[] actions = new Types.ACTIONS[2];
    int nTicks = (int) 3e7;
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    AbstractMultiPlayer player1, player2;
    player1 = new controllers.multiPlayer.sampleRandom.Agent(dg, timer, 0);
    player2 = new controllers.multiPlayer.sampleRandom.Agent(dg, timer, 1);
    int updateTick = 100;
    for (int i = 0; i < nTicks; i++) {
        // update the chosen actions every so often
        if (i % updateTick == 0) {
            actions[0] = player1.act(dg, timer);
            actions[1] = player2.act(dg, timer);
        }
        // advance anyway
        dg.advance(actions);
    }
    System.out.println(dg.getGameScore());
    System.out.println(t);
}
Also used : AbstractMultiPlayer(core.player.AbstractMultiPlayer) ElapsedTimer(utilities.ElapsedTimer) ElapsedCpuTimer(tools.ElapsedCpuTimer)

Example 22 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class SimpleBattleTest method main.

public static void main(String[] args) {
    int nSteps = (int) 2e3;
    int nPlayers = 2;
    int[] actions = new int[nPlayers];
    Random rand = new Random();
    SimpleBattleState state = new SimpleBattleState();
    state = state.copyState();
    StatSummary[] scoreStats = new StatSummary[] { new StatSummary(), new StatSummary() };
    ElapsedTimer t = new ElapsedTimer();
    BattleView view = new BattleView(state);
    if (view != null) {
        new JEasyFrame(view, "Simple Battle Game");
    }
    for (int i = 0; i < nSteps; i++) {
        for (int j = 0; j < nPlayers; j++) {
            actions[j] = rand.nextInt(state.nActions());
        }
        // now advance the game to the next step
        state.next(actions);
        for (int j = 0; j < state.score.length; j++) {
            scoreStats[j].add(state.score[j]);
        }
        if (view != null) {
            view.repaint();
            try {
                Thread.sleep(delay);
            } catch (Exception e) {
            }
        }
    }
    for (int i = 0; i < scoreStats.length; i++) {
        System.out.println("Player: " + i);
        System.out.println(scoreStats[i]);
        System.out.println();
    }
    System.out.println(t);
    System.out.println();
    System.out.println(nSteps + " states written");
}
Also used : StatSummary(utilities.StatSummary) Random(java.util.Random) JEasyFrame(utilities.JEasyFrame) ElapsedTimer(utilities.ElapsedTimer)

Example 23 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class BattleTestEA method runTrials.

public static StatSummary runTrials(EvoAlg ea, SolutionEvaluator evaluator, int nTrials, int nFitnessEvals) {
    // record the time stats
    StatSummary ss = new StatSummary();
    for (int i = 0; i < nTrials; i++) {
        ElapsedTimer t = new ElapsedTimer();
        evaluator.reset();
        System.out.println("Running trial: " + i);
        int[] solution = ea.runTrial(evaluator, nFitnessEvals);
        System.out.println(t);
        System.out.println("Solution: " + Arrays.toString(solution));
        System.out.println(evaluator.logger().ss);
        System.out.println();
        evaluator.logger().report();
        System.out.println();
        ss.add(evaluator.logger().ss.max());
    }
    return ss;
}
Also used : StatSummary(utilities.StatSummary) ElapsedTimer(utilities.ElapsedTimer)

Example 24 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class ParameterSettingsTest method main.

public static void main(String[] args) {
    DefaultParams defParams = new DefaultParams();
    defParams.shipSteer = 1;
    // GameParameters params = new GameParameters().injectValues(evolvableParams);
    GameParameters params = new GameParameters().injectValues(defParams);
    SimpleEvaluator eval = new SimpleEvaluator();
    int nTrials = 30;
    eval.evaluate(defParams, nTrials);
    // exit if we're done
    // comment this out to proceed to visual test
    // System.exit(0);
    int startLevel = 1;
    int nLives = 5;
    boolean visible = true;
    int nTicks = 10000;
    AsteroidsGameState gameState = new AsteroidsGameState().setParams(params).initForwardModel();
    Game game = new Game(gameState, visible);
    ElapsedTimer t = new ElapsedTimer();
    game.run(nTicks);
    System.out.println(t);
// System.out.println(gameState.score);
}
Also used : Game(asteroids.Game) ElapsedTimer(utilities.ElapsedTimer) AsteroidsGameState(asteroids.AsteroidsGameState)

Example 25 with ElapsedTimer

use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.

the class RandomGameVisualTest method runVisually.

public static void runVisually(ParamValues evoParams) {
    GameParameters params = new GameParameters().injectValues(evoParams);
    int startLevel = 1;
    int nLives = 5;
    boolean visible = true;
    int nTicks = 10000;
    AsteroidsGameState gameState = new AsteroidsGameState().setParams(params);
    Game game = new Game(gameState, visible);
    ElapsedTimer t = new ElapsedTimer();
    game.run(nTicks);
    System.out.println(t);
// System.out.println(gameState.score);
}
Also used : ElapsedTimer(utilities.ElapsedTimer)

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