Skip to content
Snippets Groups Projects
PiersMCTS.java 1.12 KiB
Newer Older
package battle.controllers.Piers;

import asteroids.Action;
import battle.BattleController;
import battle.SimpleBattle;

import java.util.Arrays;

/**
 * Created by pwillic on 11/06/2015.
 */
public class PiersMCTS implements BattleController {

    public PiersMCTS() {
        MCTSNode.setAllActions();
        BetterMCTSNode.setAllActions();
    @Override
    public Action getAction(SimpleBattle gameStateCopy, int playerId) {
        BetterMCTSNode root = new BetterMCTSNode(2.0, playerId);
        GameTimer timer = new GameTimer();
        timer.setTimeBudgetMilliseconds(40);
        while (timer.remainingTimePercent() > 10) {
Piers Williams's avatar
Piers Williams committed
            SimpleBattle copy = gameStateCopy.clone();
            BetterMCTSNode travel = root.select(copy, 5);
            double result = travel.rollout(copy, 50);
            travel.updateValues(result);
//        if(i % 100 == 0){
//            root.printAllChildren();
//        }
Piers Williams's avatar
Piers Williams committed
//        System.out.println("Rollouts achieved: " + i);
//        System.out.println("Best Action: " + root.getBestAction());
        return root.getBestAction();