import java.awt.Polygon;
import java.util.ArrayList;


public class DNA
{ public static final int GENE_X1 = 0; 
  public static final int GENE_Y1 = 1;
  public static final int GENE_X2 = 2;
  public static final int GENE_Y2 = 3;
  public static final int GENE_X3 = 4;
  public static final int GENE_Y3 = 5;
  public static final int GENE_RED = 6;
  public static final int GENE_BLUE = 7;
  public static final int GENE_GREEN = 8;
  public static final int GENE_ALPHA = 9;

  public static final int GENE_TYPES = 10;
  private static int[] limit = new int[GENE_TYPES];
  
  public static final double FITTNESS_UNDEFINED = -1.0;
  
  private ArrayList<Triangle> chromosome = new ArrayList<Triangle>();
  private double fitness;
  
  
  public DNA(int triangleCount)
  { fitness = FITTNESS_UNDEFINED;
    for (int i=0; i<triangleCount; i++)
    { addTriangle();
    }
  }
  
  public static void setLimits(int width, int height)
  { limit[GENE_X1] = width;
    limit[GENE_X2] = width;
    limit[GENE_X3] = width;
    limit[GENE_Y1] = height;
    limit[GENE_Y2] = height;
    limit[GENE_Y3] = height;
    limit[GENE_RED] = 255;
    limit[GENE_GREEN] = 255;
    limit[GENE_BLUE] = 255;
    limit[GENE_ALPHA] = 255;
  }
  
  public static int getLimit(int idx)
  { return limit[idx];
  }
  
  public void addTriangle()
  { chromosome.add(new Triangle());
    fitness = FITTNESS_UNDEFINED;
  }
  
  public void setTriangleGenes(int idx, int[] value)
  { fitness = FITTNESS_UNDEFINED;
    if (idx < 0 || idx >= chromosome.size()) 
    { throw new IllegalArgumentException("index out of bounds");
    }
    if (value.length != GENE_TYPES)
    { throw new IllegalArgumentException("value must be array of size "+GENE_TYPES);
    }
    
    Triangle t = chromosome.get(idx);
    for (int i=0; i<GENE_TYPES; i++)
    { t.value[i] = value[i];
    }
  }
  
  public int getTriangleCount()
  { return chromosome.size();
  }
  
  
  public int[] getTriangleGenes(int idx)
  { return chromosome.get(idx).value;
  }
  
  class Triangle
  { private int[] value = new int[GENE_TYPES];
  }
}
