Search in sources :

Example 6 with AbstractMultiPlayer

use of core.player.AbstractMultiPlayer in project SimpleAsteroids by ljialin.

the class DiffGameViewTest method main.

public static void main(String[] args) throws Exception {
    // stop the game ending
    DiffGame.maxTick = 1000000;
    DiffGame dg = new DiffGame();
    AbstractMultiPlayer player1, player2;
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    player1 = new controllers.multiPlayer.sampleRandom.Agent(dg, timer, 0);
    player2 = new controllers.multiPlayer.sampleRandom.Agent(dg, timer, 1);
    int idPlayer1 = 0;
    int idPlayer2 = 1;
    // try the evolutionary players
    int nResamples = 3;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    EvoAlg evoAlg2 = new SimpleRMHC(nResamples);
    double kExplore = 2;
    int nNeighbours = 50;
    int nEvals = 15000;
    // evoAlg = new NTupleBanditEA(kExplore, nNeighbours);
    controllers.multiPlayer.ea.Agent agentEAShift = new controllers.multiPlayer.ea.Agent(dg, timer, evoAlg, idPlayer1, nEvals);
    agentEAShift.useShiftBuffer = true;
    agentEAShift.sequenceLength = 10;
    player1 = agentEAShift;
    // player2 = new controllers.multiPlayer.discountOLMCTS.Agent(dg, timer, idPlayer2);
    // player2 = new controllers.multiPlayer.sampleOLMCTS.Agent(dg, timer, idPlayer2);
    controllers.multiPlayer.ea.Agent agentEANoShift = new controllers.multiPlayer.ea.Agent(dg, timer, evoAlg2, idPlayer1, nEvals);
    agentEANoShift.useShiftBuffer = true;
    agentEANoShift.sequenceLength = 10;
    player1 = agentEANoShift;
    int nTicks = 250;
    int delay = 100;
    int updateTick = 1;
    DiffGameView view = new DiffGameView(dg);
    JEasyFrame frame = new JEasyFrame(view, "Diff Game");
    KeyPlayer keyPlayer = new KeyPlayer(view);
    frame.addKeyListener(keyPlayer.controller);
    // player1 = keyPlayer;
    player2 = new ConstantPlayer(2);
    Types.ACTIONS[] actions = new Types.ACTIONS[2];
    for (int i = 0; i < nTicks; i++) {
        // update the chosen actions every so often
        if (i % updateTick == 0) {
            actions[0] = player1.act(dg.copy(), timer);
            actions[1] = player2.act(dg.copy(), timer);
        }
        // advance anyway
        dg.advance(actions);
        view.update(dg);
        Thread.sleep(delay);
    }
    System.out.println(dg.getGameScore());
}
Also used : AbstractMultiPlayer(core.player.AbstractMultiPlayer) EvoAlg(evodef.EvoAlg) SimpleRMHC(ga.SimpleRMHC) JEasyFrame(utilities.JEasyFrame) ElapsedCpuTimer(tools.ElapsedCpuTimer)

Example 7 with AbstractMultiPlayer

use of core.player.AbstractMultiPlayer in project SimpleAsteroids by ljialin.

the class GeneralGameRunnerTest method main.

public static void main(String[] args) {
    PlanetWarsLinkState linkState = new PlanetWarsLinkState();
    GeneralGameRunner runner = new GeneralGameRunner().setGame(linkState).setLength(200);
    AbstractMultiPlayer player1, player2;
    GameActionSpaceAdapterMulti.visual = false;
    GameState.includeBuffersInScore = false;
    int idPlayer1 = 0;
    int idPlayer2 = 1;
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    player1 = new controllers.multiPlayer.discountOLMCTS.Agent(linkState.copy(), timer, idPlayer1);
    // try the evolutionary players
    // GameActionSpaceAdapterMulti.visual = true;
    int nResamples = 1;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    int nEvals = 200;
    EvoAlg evoAlg2 = new SlidingMeanEDA().setHistoryLength(20);
    Agent evoAgent1 = new controllers.multiPlayer.ea.Agent(linkState.copy(), timer, evoAlg, idPlayer1, nEvals);
    evoAgent1.sequenceLength = 10;
    // player1 = evoAgent1;
    Agent evoAgent2 = new controllers.multiPlayer.ea.Agent(linkState.copy(), timer, evoAlg, idPlayer2, nEvals);
    evoAgent2.sequenceLength = 10;
    // evoAgent2.setUseShiftBuffer(false);
    player2 = evoAgent2;
    // 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();
    // player1 = new controllers.multiPlayer.smlrand.Agent();
    // player2 = new controllers.multiPlayer.doNothing.Agent(linkState.copy(), timer, 1);
    runner.setPlayers(player1, player2);
    int nGames = 100;
    runner.playGames(nGames);
    System.out.println(runner.scores);
}
Also used : Agent(controllers.multiPlayer.ea.Agent) AbstractMultiPlayer(core.player.AbstractMultiPlayer) SlidingMeanEDA(ntuple.SlidingMeanEDA) EvoAlg(evodef.EvoAlg) SimpleRMHC(ga.SimpleRMHC) ElapsedCpuTimer(tools.ElapsedCpuTimer)

Aggregations

AbstractMultiPlayer (core.player.AbstractMultiPlayer)7 ElapsedCpuTimer (tools.ElapsedCpuTimer)7 EvoAlg (evodef.EvoAlg)5 SimpleRMHC (ga.SimpleRMHC)5 Random (java.util.Random)3 Types (ontology.Types)3 ElapsedTimer (utilities.ElapsedTimer)3 Agent (controllers.multiPlayer.ea.Agent)2 StateObservationMulti (core.game.StateObservationMulti)2 SlidingMeanEDA (ntuple.SlidingMeanEDA)2 JEasyFrame (utilities.JEasyFrame)2 StatSummary (utilities.StatSummary)2 BattleView (battle.BattleView)1 PlanetWarsLinkState (gvglink.PlanetWarsLinkState)1 CompactSlidingModelGA (ntuple.CompactSlidingModelGA)1 NTupleBanditEA (ntuple.NTupleBanditEA)1 DiffGame (numbergame.DiffGame)1 GameState (planetwar.GameState)1 PlanetWarView (planetwar.PlanetWarView)1