Search in sources :

Example 1 with PlanetWarView

use of planetwar.PlanetWarView in project SimpleAsteroids by ljialin.

the class PlanetWarsLinkTest method runTest.

public static double runTest() throws Exception {
    PlanetWarsLinkState state = new PlanetWarsLinkState();
    // state.state.
    GameState.includeBuffersInScore = true;
    PlanetWarView view = null;
    view = new PlanetWarView((GameState) state.state);
    // JEasyFrame frame = new JEasyFrame(view, "Simple Planet Wars");
    // KeyController controller = new KeyController();
    // frame.addKeyListener(controller);
    // now play
    Random random = new Random();
    AbstractMultiPlayer player1, player2;
    GameActionSpaceAdapterMulti.visual = false;
    // DefaultMutator.totalRandomChaosMutation = true;
    // controllers.singlePlayer.sampleOLMCTS.Agent olmcts =
    // new controllers.singlePlayer.sampleOLMCTS.Agent(linkState, timer);
    int idPlayer1 = 0;
    int idPlayer2 = 1;
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    player2 = new controllers.multiPlayer.discountOLMCTS.Agent(state.copy(), timer, idPlayer2);
    // player2 = new controllers.multiPlayer.sampleOLMCTS.Agent(state.copy(), timer, idPlayer2);
    // try the evolutionary players
    int nResamples = 1;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    int nEvals = 133;
    // evoAlg = new SlidingMeanEDA().setHistoryLength(20);
    Agent evoAgent = new controllers.multiPlayer.ea.Agent(state.copy(), timer, evoAlg, idPlayer1, nEvals);
    evoAgent.sequenceLength = 15;
    evoAgent.setUseShiftBuffer(true);
    player1 = evoAgent;
    // player2 = new controllers.multiPlayer.ea.Agent(linkState, timer, evoAlg2, idPlayer2, nEvals);
    // player2 = new controllers.multiPlayer.ea.Agent(linkState, timer, new SimpleRMHC(nResamples), idPlayer2, nEvals);
    // player1 = new controllers.multiPlayer.smlrand.Agent();
    // player2 = new controllers.multiPlayer.smlrand.Agent();
    // player2 = new controllers.multiPlayer.doNothing.Agent(state, timer, 1);
    // EvoAlg evoAlg2 = new SimpleRMHC(2);
    // player1 = new controllers.multiPlayer.ea.Agent(linkState, timer, evoAlg2, idPlayer1, nEvals);
    // player1 =
    // in milliseconds
    int thinkingTime = 50;
    int delay = 200;
    // player = new controllers.singlePlayer.sampleRandom.Agent(stateObs, timer);
    // check that we can play the game
    int nSteps = 200;
    view = null;
    for (int i = 0; i < nSteps; i++) {
        timer = new ElapsedCpuTimer();
        timer.setMaxTimeMillis(thinkingTime);
        Types.ACTIONS action1 = player1.act(state.copy(), timer);
        timer = new ElapsedCpuTimer();
        timer.setMaxTimeMillis(thinkingTime);
        Types.ACTIONS action2 = player2.act(state.copy(), timer);
        // §action2 =
        state.advance(new Types.ACTIONS[] { action1, action2 });
        if (view != null) {
            view.update((GameState) state.state);
            Thread.sleep(delay);
        }
    // System.out.println("Game tick: " + i);
    }
    System.out.println("Game Score: " + state.getGameScore());
    // System.out.println("MCTS Evals: " + TreeNode);
    return state.getGameScore() > 0 ? 1 : 0;
}
Also used : PlanetWarView(planetwar.PlanetWarView) Agent(controllers.multiPlayer.ea.Agent) Types(ontology.Types) AbstractMultiPlayer(core.player.AbstractMultiPlayer) GameState(planetwar.GameState) EvoAlg(evodef.EvoAlg) Random(java.util.Random) SimpleRMHC(ga.SimpleRMHC) ElapsedCpuTimer(tools.ElapsedCpuTimer)

Aggregations

Agent (controllers.multiPlayer.ea.Agent)1 AbstractMultiPlayer (core.player.AbstractMultiPlayer)1 EvoAlg (evodef.EvoAlg)1 SimpleRMHC (ga.SimpleRMHC)1 Random (java.util.Random)1 Types (ontology.Types)1 GameState (planetwar.GameState)1 PlanetWarView (planetwar.PlanetWarView)1 ElapsedCpuTimer (tools.ElapsedCpuTimer)1