package edu.berkeley.nlp.starcraft.strategies;

import org.bwapi.proxy.model.UnitType;

import edu.berkeley.nlp.starcraft.Action;
import edu.berkeley.nlp.starcraft.ActionProposal;
import edu.berkeley.nlp.starcraft.ActionProposer;
import edu.berkeley.nlp.starcraft.ActionScorer;
import edu.berkeley.nlp.starcraft.Strategy;
import edu.berkeley.nlp.starcraft.actions.BackgroundAction;
import edu.berkeley.nlp.starcraft.actions.MicroSquadAction;
import edu.berkeley.nlp.starcraft.actions.ZerglingSquadAction;
import edu.berkeley.nlp.starcraft.actions.scorers.ConstantScorer;
import edu.berkeley.nlp.starcraft.actions.scorers.ReScorer;
import edu.berkeley.nlp.starcraft.model.Model;
import edu.berkeley.nlp.starcraft.model.clusters.MicroTestClusterManager;
import edu.berkeley.nlp.starcraft.resources.ResourceProfile;

public class MicroStrategy implements Strategy {
	private BackgroundAction backgroundAction;

	@Override
	public Action getBackgroundAction() {
		if (backgroundAction == null) {
			Model.getInstance().opponentTracker.setClusterManager(new MicroTestClusterManager());
			backgroundAction = new BackgroundAction();
			Action zergling_micro = new ZerglingSquadAction(dummyProposal("Squad"), UnitType.ZERG_ZERGLING);
			backgroundAction.registerAction(UnitType.ZERG_ZERGLING, zergling_micro);
			Action mutalisks = new MicroSquadAction(dummyProposal("squad"), UnitType.ZERG_MUTALISK);
			backgroundAction.registerAction(UnitType.ZERG_MUTALISK, mutalisks);
		}
		return backgroundAction;
	}

	@Override
	public ActionProposer getProposer() {
		return new ZerglingSquadAction.Proposer(UnitType.ZERG_ZERGLING);
	}

	private ActionProposal dummyProposal(String name) {
		return new ActionProposal(name, 0, new ResourceProfile()) {

			@Override
			protected Action createInstantiation() {
				return null;
			}

		};
	}

	@Override
	public ActionScorer getScorer() {
		return new ReScorer(new ConstantScorer(1.0));
	}

}
