Search in sources :

Example 1 with PlanetWarsLinkState

use of gvglink.PlanetWarsLinkState in project SimpleAsteroids by ljialin.

the class GameRunnerTest method getMCTSAgent.

static GVGAIWrapper getMCTSAgent(GameState gameState, int playerId) {
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    PlanetWarsLinkState linkState = new PlanetWarsLinkState(gameState);
    AbstractMultiPlayer agent = new controllers.multiPlayer.discountOLMCTS.Agent(linkState.copy(), timer, playerId);
    GVGAIWrapper wrapper = new GVGAIWrapper().setAgent(agent);
    return wrapper;
}
Also used : AbstractMultiPlayer(core.player.AbstractMultiPlayer) ElapsedCpuTimer(tools.ElapsedCpuTimer) PlanetWarsLinkState(gvglink.PlanetWarsLinkState)

Example 2 with PlanetWarsLinkState

use of gvglink.PlanetWarsLinkState in project SimpleAsteroids by ljialin.

the class EvoSequenceTest method main.

// simple example of NOT doing rolling horizon, but instead
// of evolving a complete sequence
public static void main(String[] args) throws Exception {
    GameState game = new GameState().defaultState();
    int nResamples = 1;
    EvoAlg evoAlg = new SimpleRMHC(nResamples);
    int nEvals = 2000;
    int seqLength = 30;
    // evoAlg = new SlidingMeanEDA().setHistoryLength(20);
    System.out.println("Initial score: " + game.getScore());
    EvoAgent evoAgent = new EvoAgent().setEvoAlg(evoAlg, nEvals).setSequenceLength(seqLength);
    int[] seq = evoAgent.getActions(game.copy(), 0);
    // System.out.println(evoAgent.simpleGameAdapter.logger().fa);
    // new JEasyFrame( LineChart.easyPlot(evoAgent.simpleGameAdapter.logger().fa), "Evo Plot");
    // visiPlay(game, seq);
    // check the sequence fitness
    System.out.println(evoAgent.simpleGameAdapter.logger().ss);
    System.out.println("Returned sequence: " + Arrays.toString(seq));
    for (int i = 0; i < 5; i++) {
        System.out.println(evoAgent.simpleGameAdapter.evaluate(seq));
    }
    System.out.println();
    System.out.println("Now using the other one");
    for (int i = 0; i < 5; i++) {
        PlanetWarsLinkState linkState = new PlanetWarsLinkState(game.copy());
        GameActionSpaceAdapterMulti adapter = new GameActionSpaceAdapterMulti(linkState, seqLength, 0, 1);
        System.out.println(adapter.evaluate(seq));
    }
    System.out.println();
    for (int i = 0; i < 5; i++) {
        System.out.println(evoAgent.simpleGameAdapter.evaluate(seq));
    }
    System.out.println();
}
Also used : SimpleRMHC(ga.SimpleRMHC) GameActionSpaceAdapterMulti(evodef.GameActionSpaceAdapterMulti) PlanetWarsLinkState(gvglink.PlanetWarsLinkState) EvoAlg(evodef.EvoAlg)

Example 3 with PlanetWarsLinkState

use of gvglink.PlanetWarsLinkState in project SimpleAsteroids by ljialin.

the class GVGAIWrapper method getAction.

@Override
public int getAction(AbstractGameState gameState, int playerId) {
    PlanetWarsLinkState linkState = new PlanetWarsLinkState(gameState);
    ElapsedCpuTimer timer = new ElapsedCpuTimer();
    timer.setMaxTimeMillis(thinkingTime);
    Types.ACTIONS actions = agent.act(linkState, timer);
    return actions.ordinal();
}
Also used : Types(ontology.Types) PlanetWarsLinkState(gvglink.PlanetWarsLinkState) ElapsedCpuTimer(tools.ElapsedCpuTimer)

Aggregations

PlanetWarsLinkState (gvglink.PlanetWarsLinkState)3 ElapsedCpuTimer (tools.ElapsedCpuTimer)2 AbstractMultiPlayer (core.player.AbstractMultiPlayer)1 EvoAlg (evodef.EvoAlg)1 GameActionSpaceAdapterMulti (evodef.GameActionSpaceAdapterMulti)1 SimpleRMHC (ga.SimpleRMHC)1 Types (ontology.Types)1