Search in sources :

Example 1 with GameState

use of planetwar.GameState 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)

Example 2 with GameState

use of planetwar.GameState in project SimpleAsteroids by ljialin.

the class PlanetWarsLinkStateDebug method main.

// currently the link state is not working properly
// this class will help to debug it
public static void main(String[] args) throws Exception {
    int seed = 4;
    // problem has now been identified
    // 
    GameState gameState = new GameState().defaultState(seed);
    PlanetWarsLinkState linkState = new PlanetWarsLinkState(gameState);
    System.out.println(PlanetWarsLinkState.actions);
    int[] a1 = new int[] { 0, 1, 2, 3, 2, 1, 3, 3, 2, 4, 2, 4 };
    int[] a2 = new int[] { 1, 0, 0, 4, 3, 1, 3, 3, 2, 4, 2, 4 };
    for (int i = 0; i < a1.length; i++) {
        gameState.next(new int[] { a1[i], a2[i] });
        Types.ACTIONS[] la = new Types.ACTIONS[] { PlanetWarsLinkState.actions.get(a1[i]), PlanetWarsLinkState.actions.get(a2[i]) };
        // linkState.advance(la);
        System.out.println("Link state: " + linkState.getGameScore());
        System.out.println("Game state: " + gameState.getScore());
        System.out.println();
    }
}
Also used : GameState(planetwar.GameState)

Aggregations

GameState (planetwar.GameState)2 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 PlanetWarView (planetwar.PlanetWarView)1 ElapsedCpuTimer (tools.ElapsedCpuTimer)1