/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tileworld;

import java.io.FileWriter;
import java.io.IOException;
import sun.org.mozilla.javascript.internal.ast.ForInLoop;

/**
 *
 * @author Jakub
 * Tests the generated agents in the environment
 */
public class Test2 {
    public static void main(String[] args) throws IOException {
        
      TileworldMain a = new TileworldMain(); 
      FileWriter writer = new FileWriter("test.csv");
      
      int n=100; //number of trials  
      int[] variance=new int[n];
      double vari;
       
      int result =0;
      int k=0;
      int res=0;
      
      //environment 1 test
      writer.append("=================================Environment 1 test==================================\n");
      System.out.println("=================================Environment 1 test==================================");
      double tileMean = 0.2;double holeMean = 0.2;double obstacleMean = 0.2;double tileDev = 0.05f;double holeDev = 0.05f;
      double obstacleDev = 0.05f; int lifeTime = 100; int xDimension=100; int yDimension=100;
      result=0;      
       for (int j = 0; j < n; j++) {
           res= a.runTest2(tileMean, tileDev, holeMean, holeDev,  obstacleMean, obstacleDev,lifeTime,xDimension,yDimension);
           variance[j]=res;
           result+=res;
           System.out.println(res);
       }
      vari=0;
        for (int i = 0; i < variance.length; i++) {
           vari += (variance[i]-result/n)*(variance[i]-result/n);
            
        }
       
       writer.append("Score = "+result/n+"\n");
        System.out.println("Score = "+result/n+ " Variance="+vari/n);
    
      //environment 2 test
        writer.append("=================================Environment 2 test==================================\n");
      System.out.println("=================================Environment 2 test==================================");
      tileMean = 2;holeMean = 2;obstacleMean = 2;tileDev = 0.5f;holeDev = 0.5f;
      obstacleDev = 0.5f; lifeTime = 30; xDimension=50; yDimension=50;
      result=0;
      for (int j = 0; j < n; j++) {
          res= a.runTest2(tileMean, tileDev, holeMean, holeDev,  obstacleMean, obstacleDev,lifeTime,xDimension,yDimension);
          variance[j]=res;
           result+=res;
           System.out.println(res);
      }
      vari=0;
        for (int i = 0; i < variance.length; i++) {
           vari += (variance[i]-result/n)*(variance[i]-result/n);
            
        }
      writer.append("Score = "+result/n+"\n");
      System.out.println("Score = "+result/n + " Variance="+vari/n);
    
      //environment 3 test
      writer.append("=================================Environment 3 test==================================\n");
      System.out.println("=================================Environment 3 test==================================");
      tileMean = 0.02;holeMean = 0.2;obstacleMean = 0.5;tileDev = 0.001f;holeDev = 0.01f;
      obstacleDev = 0.1f; lifeTime = 120; xDimension=150; yDimension=40;
      result=0;
      for (int j = 0; j < n; j++) {
          res= a.runTest2(tileMean, tileDev, holeMean, holeDev,  obstacleMean, obstacleDev,lifeTime,xDimension,yDimension);
          System.out.println(res);
          variance[j]=res;
           result+=res;
      }
      vari=0;
        for (int i = 0; i < variance.length; i++) {
           vari += (variance[i]-result/n)*(variance[i]-result/n);
            
        }
      
      writer.append("Score = "+result/n+"\n");
      System.out.println("Score = "+result/n + " Variance="+vari/n);
      
      
      //Default values      
       xDimension=50; yDimension=50; tileDev = 0.05f;holeDev = 0.05f;obstacleDev = 0.05f;
      n=10;
      
      
      
      //Lifetime
     
      
      System.out.println("Lifetime");
      writer.append("=================================Lifetime==================================\n");
      writer.append("Lifetime,Score\n");
      int max=150;
      double step=1;
      double i=0;
      while (i<max) {
            i+=step;
            
            result=0;            
            for (int j = 0; j < n; j++) result+= a.runTest2(Parameters.tileMean, tileDev, Parameters.holeMean, holeDev,  Parameters.obstacleMean, obstacleDev,(int) i,xDimension,yDimension);
             writer.append(i+","+result/n+"\n");   
             System.out.println(i+","+result/n);  
      }
      
      
      
      //Tile mean
      lifeTime=30;
      xDimension=50; yDimension=50;
      System.out.println("=================================Tile mean, Hole mean, Obstacle mean, Density; Lifetime=30; Dimension=50 ==================================\n");
      writer.append("=================================Tile mean, Hole mean, Obstacle mean, Density; Lifetime=30; Dimension=50 ==================================\n");
      writer.append("Value,Tile mean,Hole mean,Obstacle mean,Density\n");
      max=10; //max mean lifetime
      step=0.1;
      i=5.8;
      String s="";
      while (i<max) {
            i+=step;            
            result=0;
            s=i+",";
            for (int j = 0; j < n; j++) result+= a.runTest2(i, tileDev, Parameters.holeMean, holeDev,  Parameters.obstacleMean, obstacleDev, lifeTime,xDimension,yDimension);
            
            s+=result/n+",";
            result=0;
            for (int j = 0; j < n; j++) result+= a.runTest2(Parameters.tileMean, tileDev, i, holeDev,  Parameters.obstacleMean, obstacleDev, lifeTime,xDimension,yDimension);
            s+=result/n+",";
            result=0;
            for (int j = 0; j < n; j++) result+= a.runTest2(Parameters.tileMean, tileDev, Parameters.holeMean, holeDev,  i, obstacleDev, lifeTime,xDimension,yDimension);
            s+=result/n+",";
             writer.append(s+"\n");   
             System.out.println(s);
      }
      
      
      
     //Tile mean, lifetime = 100
      lifeTime=100;
      xDimension=100; yDimension=100;
      System.out.println("=================================Tile mean, Hole mean, Obstacle mean, Density; Lifetime=100; Dimension=100 ==================================\n");
      writer.append("=================================Tile mean, Hole mean, Obstacle mean, Density; Lifetime=100 ==================================\n");
      writer.append("Value,Tile mean,Hole mean,Obstacle mean,Density\n");
      i=0;
      s="";
      while (i<max) {
            i+=step;            
            result=0;
            s=i+",";
            for (int j = 0; j < n; j++) result+= a.runTest2(i, tileDev, Parameters.holeMean, holeDev,  Parameters.obstacleMean, obstacleDev, lifeTime,xDimension,yDimension);
            s+=result/n+",";
            result=0;
            for (int j = 0; j < n; j++) result+= a.runTest2(Parameters.tileMean, tileDev, i, holeDev,  Parameters.obstacleMean, obstacleDev, lifeTime,xDimension,yDimension);
            s+=result/n+",";
            result=0;
            for (int j = 0; j < n; j++) result+= a.runTest2(Parameters.tileMean, tileDev, Parameters.holeMean, holeDev,  i, obstacleDev, lifeTime,xDimension,yDimension);
            s+=result/n+",";
            result=0;
            for (int j = 0; j < n; j++) result+= a.runTest2(i, tileDev, i, holeDev,  i, obstacleDev, lifeTime,xDimension,yDimension);
            
            s+=result/n;
            
            writer.append(s+"\n");   
             System.out.println(s);
      }
      
     
        
        
      
      writer.flush();
        writer.close();
        
    }
    
}
