/*
 * Created on Nov 22, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package jone;
import java.util.Random;
import java.awt.geom.Point2D;
/**
 * @author brian
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Brain {
	private FeedForwardNeuralNet neuralNet;

	public Brain(int [] numNeuronsInEachLayer, 
			int [] neuronTypesForLayers, int inputsize,int outputsize)
	{	
		neuralNet = new FeedForwardNeuralNet(numNeuronsInEachLayer,
				neuronTypesForLayers,inputsize,outputsize);	
	}
	
	private Brain(FeedForwardNeuralNet net)
	{
		neuralNet = net;
	}
	public Brain mutate(double probType)
	{
		FeedForwardNeuralNet nn;
		Random random = RandomSingleton.getDefaultInstance(); 
		if(random.nextDouble() > probType)
			nn = neuralNet.swapWeights(.1);
		else
			nn = neuralNet.addNoiseToWeights(.1,random.nextDouble());
		return new Brain(nn);
	}
	
	public static Brain splice(double biasForP1, Brain b1, Brain b2)
	{
		return new Brain(new FeedForwardNeuralNet(biasForP1, 
				b1.neuralNet, b2.neuralNet));
	}
	
	public Point2D.Double think(double [] input) 
	{
		double [] direction = this.neuralNet.computeOutput(input,true);
		return new Point2D.Double(direction[0],direction[1]);
	}
	
		
	}

