/*
 * Cortex.java
 *
 * Created on 4 of August 2004, 22:21
 */
/**
 *
 * @author Paulo Roque Silva
 */
import java.io.*;

public class Cortex implements Serializable {
    public static final long serialVersionUID = 2025L;
    // Vers�o dos dados
    static String			Name; // Nome
    static String			EmailPhone; // Email - Telefone           
    static String			Password; // Senha
    static final int 	    ThresholdTaste   = 90;
    static final int 	    ThresholdVision  = 98;
    static final int 	    ThresholdTact    = 80;
    static final int 	    ThresholdSound   = 97;
    static final int 	    ThresholdSmell   = 80;
    static final int 	    ThresholdProSelf = 80;
    static final int 	    ThresholdAct  = 10;
    static int              Senses; // N�mero de sentidos
    public static boolean	Warn; // Avisa se verdadeiro
    public static boolean	Born; // True se nasceu
    public static boolean	Thumb; // Tipo de robô
	public static int		nSpeaks;;
    // Se verdade polegar esquerdo em cima ou
    // se falso polegar direito em cima
    int						[]threshold = {
    						ThresholdTaste,
    						ThresholdVision,
    						ThresholdTact,
    						ThresholdSound,
    						ThresholdSmell,
    						ThresholdProSelf
    						};
    public static int		exec; // Executado
    public static int 		lastExec;
    						// Executado antes do exec
    public static int 		lastQuality;
    int						nNeuronsAct,
    						// N�mero de neur�nios no Act
    						nNeuronsTime,
    						// N�mero de neur�nios do
    						// Remember e Sleep
    						actual; // Passo atual
    long					timeLife,
    // Tempo em milisegundos de vida do Liberu executando
    						bornTime,
    						// Data de nascimento - (ms)
    						timeLifeReal,
    						// Tempo de vida do rob� - (ms)
    						timeBefore;
    Neuron		  			[][]time;
    						// Rede do passado - Remember
    Neuron					[]actNode;
    						// Rede dos que agem - Act
    Neuron					[]hemisphereLeft;
    //Hemisf�rio esquerdo do Cerebellum
    Neuron					[]hemisphereRigth;
    //Hemisf�rio direito do Cerebellum

    /** Creates a new instance of Cortex */
    public Cortex(int t, int nAct, int nPast) {
        int i, n;    // indexes
	
        Name = new String();
        EmailPhone = new String();
        Password = new String();
        Born = false;
        Thumb = false;
        Senses   = t;
        nNeuronsAct = nAct;
        nNeuronsTime = nPast;
        actual = 0;
        timeLife = 0;
        bornTime = 0;
        timeBefore = 0;
        exec = 0;
        lastExec = 0;
        lastQuality = 0;
    	nSpeaks		 = 0;
        time = new Neuron[nNeuronsTime][Senses];
	    for (i=0; i<Senses; i++)
	           for (n=0; n<nNeuronsTime; n++)
	        		   time[n][i] = new Neuron(n,
	        				   threshold[i]);
        actNode = new Neuron[nNeuronsAct];
        for (n=0; n<nNeuronsAct; n++) 
        	actNode[n] = new Neuron(n, ThresholdAct);
        hemisphereLeft = new Neuron[nNeuronsTime];
        hemisphereRigth = new Neuron[nNeuronsTime];
	    for (n=0; n<nNeuronsTime; n++) {
	    	hemisphereLeft[n] = new Neuron(n,
	    			ThresholdProSelf);
	    	hemisphereRigth[n] = new Neuron(n,
	    			ThresholdProSelf);
	    }
	    Warn = false;
    }
    
    public int addDataActual() {
    	
    	actual += 1;
    	return actual;
    }
    
    private long getTime() {
    	
    	return System.currentTimeMillis();
    }

    public long bornTime() {
    	
        timeLife = getTime();
    	return bornTime = timeLife;
    }

    public long addTime() { // Retorna tempo vida real (ms)
    	
    	return timeLifeReal += getTime() - timeLife;
    }

    public long startTime() { // Marca o ponto de execu��o
    	
    	timeBefore = timeLife;
    	return timeLife = getTime();
    }
    
    public long getCicle() {
    	
    	return (timeLife - timeBefore);
    }
}