public static void formatResults(ArrayList<TetrisAgent[]> generations, String file)
 {
        BufferedWriter writer = null;
  try
  {
         writer =  new BufferedWriter(new FileWriter(file, false));
  }
  catch(IOException ex){ex.printStackTrace();}
  
  int gens = generations.size();
  
  //header
  for(int i = 0; i < gens; i++)
  {
   try 
   {
    if (i == gens - 1) 
     writer.write("g" + i + "\n");
    else 
     writer.write("g" + i + ",");
   }
   catch (IOException ex){ex.printStackTrace();}
  }
  
  int pop = generations.get(0).length;
  for(int indiv = 0; indiv < pop; indiv++)
  {
   //dados
   for(int i = 0; i < gens; i++)
   {
    TetrisAgent agent = generations.get(i)[indiv];
    float fitness = agent.fitness;
    
    try 
    {
     if (i == gens - 1) 
      writer.write(fitness + "\n");
     else 
      writer.write(fitness + ",");
    }
    catch (IOException ex){ex.printStackTrace();}
   }
        }
        try
        {
         writer.close();
        }
        catch(IOException ex){ex.printStackTrace();}
 }