import org.w2mind.net.RunError;
import org.w2mind.net.Mind;
import org.w2mind.soml.Date;
import org.w2mind.net.Description;
import org.w2mind.tyrrell.State;
import org.w2mind.tyrrell.UsefulConstants;

/**
	In order to create a mind for Tyrrell's world you must do the following:
	<ol>
		<li>Make a copy of this source file and give it a unique name. You should probably use
		 your user name, and a unique identifier if you submit more than one e.g. package org.w2mind.tyrrell.submind.jswan_1</li>
		<li>Change the code to select an action 0-34 in the getaction method. At the moment this method will return a random action</li>
		<li>Put any startup code in the newrun method</li>
		<li>Put any cleanup code in the endrun method</li>
		<li>Change the getdescription method to return your name, e-mail, description of this code, the date this was created and the date this was last modified</li>
		<li>Run this mind in the world, as described in the web site</li>
	</ol>
*/
public class SampleSubMind implements Mind {

	/**
		Constructor for the mind. If you are using a separate class you might want to instantiate it here.
	*/
	public void newrun() throws RunError {
		try {
			// put the constructor information in here
		} catch (Exception e) {
			throw new RunError("400", "Could not start mind (" + e.getMessage() + ")");
		}
	}

	/**
		This method is called at every time step. It should return a single action, i.e. a number between 0 and 34 as listed 
		on the web site. This number is wrapped in an Action object, as shown in the sample code
	*/
	public org.w2mind.net.Action getaction(org.w2mind.net.State s) throws RunError {
		try {
			
			// this gives a representation of the state for Tyrrell's world.
			// You should see the javadoc information on this state to see how it is represented.
			State state = new State(s.toString());

			int action = (int)(Math.random() * 35); // sleeping

			// you can select a specific action from Constants using
			// action = UsefulConstants.MATING;

			// select the goal that you are following: this should be one of: 
			/*
				CLEANING
				OBTAINING_FOOD
				OBTAINING_WATER
				TEMPERATURE_REGULATION
				PREDATOR_AVOIDANCE
				VIGILENCE
				HAZARD_AVOIDANCE
				IRRELEVANT_ANIMAL_AVOIDANCE
				SLEEPING_AT_NIGHT
				STAYING_CLOSE_TO_COVER
				NOT_GETTING_LOST
				REPRODUCTION
				UNKNOWN
			*/
			String goal = "CLEANING";

			// select the ectimated number of steps for which you will need control to pursue and satisfy this goal:
			int steps = 3;

			// this sets the action to be 
			return new org.w2mind.net.GoalStepsAction("" + action, goal, steps);

		} catch (Exception e) {
			e.printStackTrace();
			throw new RunError("400", "Could not get new action in mind (" + e.getMessage() + ")");
		}
	}
	
	/**
		This method is called at the end, when the animal has died.
	*/
	public void endrun() throws RunError {
		try {
			// put all descruction information here
		} catch (Exception e) {
			throw new RunError("400", "Could not end run in mind (" + e.getMessage() + ")");
		}
	}
	
	/**
		This returns a description of the mind, that will be used to store your details in the score board.
	*/
	public Description getdescription() throws RunError {
		try {
			return new Description(
				// your name
				"Ciaran O'Leary", 
				
				// your e-mail address
				"Ciaran.OLeary@comp.dit.ie", 

				// a brief description of the mind
				"This is the description of a sample mind - you might want to include some information on " +
				"the algorithm that you use here.", 
					
				// the date the mind was created
				new Date(27, 02, 1900), 
					
				// the date the mind was last modified
				new Date(13, 06, 1950));

		} catch (Exception e) {
			throw new RunError("400", "Could not get description (" + e.getMessage() + ")");
		}
	}
}

