package edu.calpoly.csc480.Corral.Agent;

import java.util.*;

import edu.calpoly.csc480.Corral.Agent.*;
import edu.calpoly.csc480.Corral.Agent.InformedAgent.*;
import edu.calpoly.csc480.Corral.Agent.UninformedAgent.*;

public class Agents {
	static protected AgentLink agents[];
	static protected String agentNames[];

	static {
		agents = new AgentLink[] {
			new AgentLink(new DeepAgent()),
			new AgentLink(new IDAgent()),
			new AgentLink(new GreedyAgent()),
			new AgentLink(new StarAgent()),
		};
	
		agentNames = new String[agents.length];
		
		for (int ndx = 0; ndx < agents.length; ndx++) {
			agentNames[ndx] = agents[ndx].name;
		}
	}

	static public String[] getNames() {return agentNames;}

	static public BaseMeans makeMeans(String name) {
		BaseAgent agent = null;
		
		for (int ndx = 0; ndx < agents.length && agent == null; ndx++) {
			if (agents[ndx].name.equals(name)) {
				agent = agents[ndx].newInstance();
			}
		}
		
		return agent.makeMeans();
	}

	static protected class AgentLink {
		public AgentLink(BaseAgent agent) {
			this.agentClass = agent.getClass();
			this.name       = newInstance().getName();
		}
		
		public BaseAgent newInstance() {
			BaseAgent agent = null;
			
			try {
				agent = (BaseAgent)agentClass.newInstance();
			} catch (Exception err) {err.printStackTrace();}
			
			return agent;
		}
		
		public Class agentClass;
		public String name;
	}

	protected Agents() {
	}
}