/*
 * 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 = 2015L; // Data version
    static String			Name; // Name
    static String			EmailPhone; // email or phone           
    static String			Password; // password
    static final int 	    ThresholdTaste   = 98; // Threshold percentage to fire neuron
    static final int 	    ThresholdVision  = 96; //97 NXT Threshold percentage to fire neuron
    static final int 	    ThresholdTact    = 90; // Threshold percentage to fire neuron
    static final int 	    ThresholdSound   = 95; // Threshold percentage to fire neuron
    static final int 	    ThresholdSmell   = 95; // Threshold percentage to fire neuron
    static final int 	    ThresholdProSelf = 90; // Threshold percentage to fire neuron
    static final int 	    ThresholdAct  = 90;	   // Threshold percentage to fire neuron
    static int              Senses; // #Trails of the Net (#Senses + Proprioception)
    public static boolean	Warn; // warn if true
    int						[]threshold = {
    						ThresholdTaste,
    						ThresholdVision,
    						ThresholdTact,
    						ThresholdSound,
    						ThresholdSmell,
    						ThresholdProSelf
    						};
    int						nNeuronsAct, // #Acting Neurons
    						nNeuronsTime, // #Neurons of the Net Time
    						actual; // actual step as equal as PlayLiberu.nStep
    long					timeLife, // Time in mili-seconds of life of Liberu running
    						bornTime, // BORN TIME - (ms)
    						timeLifeReal; // LIFE REAL - (ms)
    Neuron		  			[][]time; // net of Past time neurons
    Neuron					[]actNode; // net of Cerebellum acting neurons
    Neuron					[]hemisphereLeft; //hemisphere  net of Cerebellum Left neurons
    Neuron					[]hemisphereRigth; // net of Cerebellum Rigth neurons

    /** Creates a new instance of Net */
    public Cortex(int t, int nAct, int nPast) {
        int i, n;    // indexes
	
        Name = new String();
        EmailPhone = new String();
        Password = new String();
        Senses   = t;
        nNeuronsAct = nAct;
        nNeuronsTime = nPast;
        actual = 0;
        timeLife = 0;
        bornTime = 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() { // returns time live mili-seconds
    	
    	return timeLifeReal += getTime() - timeLife;
    }

    public long startTime() { // marks a point of execution
    	
    	return timeLife = getTime();
    }
    
    public long getCicle() {
    	
    	return (getTime() - timeLife);
    }
}