com.evoluzion.World Maven / Gradle / Ivy
                 Go to download
                
        
                    Show more of this group  Show more artifacts with this name
Show all versions of Evoluzion-diploid Show documentation
                Show all versions of Evoluzion-diploid Show documentation
The Evoluzion-diploid module
                
             The newest version!
        
        /*Copyright 2014 Adolfo R. Zurita*/
/*This file is part of EvoluZion.
 EvoluZion is free software: you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 EvoluZion is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Lesser General Public License for more details.
 You should have received a copy of the GNU Lesser General Public License
 along with EvoluZion.  If not, see  .*/
package com.evoluzion;
import java.awt.HeadlessException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.TimeUtils;
public class World implements Serializable {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	protected Evoluzion ev;// clase prinsipal
	StartMenu mi; // menu inicio
	Text tx;
	//Virus virus = new Virus(20,20,10,95); 
	Array ase, ase1, ase2, ase3, ase4, ase5, ase6, ase7, ase8, ase9,
			ase10; // lista de energia verde
	Array aqe, aqe1, aqe2, aqe3, aqe4, aqe5, aqe6, aqe7, aqe8, aqe9,
			aqe10; // lista de energia roja (biomasa)
	Array organisms; // lista de organismos
	Array aEspesies, aEspesiesTotales; // listas de organismos
	// colectados segun especies
	Array aAlelos;
	Array aFenotipos;
	Array aGenotipos;
	float ancho, alto, ratio; // dimenciones de la pantalla
	//
	float deltaX = 0; // delta de x entre dos individuos
	float deltaY = 0; // delta de y entre dos individuos
	float medSpeed; // se usa para el calcula de velosidad media
	double temperatura = 25;
	double medTem;
	float efficiency = 1;
	// suma de toda la masa libre
	int dias, horas, minutos, minutes2, minutos3, seconds, segundos2,
			segundos3, seconds4, segundos5, segundos6; // anota el paso del
	// tiempo
	long edad, delta, delta2, delta3, tiempo; // mide diferencia de tiempo entre
	// una accion y la siguiente
	int maxTime = 0;
	double Masatotal, MasatotalL, MasatotalR;
	int tiempoMuestreo;
	int tiempoCatastrofe;
	int tiempoATB;
	int cantidadMuestras;
	int contadorMuestreo;
	int Senergia;
	int Qbiomasa;
	int numOrg;
	int numSen;
	int numQen;
	int numSenR;
	int numQenR;
	int SenergiaR;
	int QbiomasaR;
	int EnRe;
	int BioRe;
	float medSize;
	int medMut;
	int medLon;
	int pausaGame = 1;// 1= play -1=stop
	float zoom = 2;
	int index = 0;
	int maximo = 1000; // numero maximo de organismos
	int ingles = -1; // -1=false 1=true
	int indice = 0, indiceDer = 0, indiceIz = 0; // se usa para ordenar los
													// organismos al final de la
													// partida
	
	
	float minStar1, minStar2;
	float TempFinal1, TempFinal2, tempXSecond1, tempXSecond2;
	float deltaTime1, deltaTime2;
	float salud;
	// hotSpot for crossover
	int gap1, gap2, gap3, gap4, gap5, gap6, gap7, gap8, gap9, gap92, gap10,
			gap11;
	int antibiotico = -1; // 1= true -1= false
	int numero = 0; // es usado por metodos que cuentan cosas
	int id = 0; // es usado por metodos que cuentan cosas
	int cantidad = 0;// es usado por metodos que cuentan cosas
	int numeroI = 0; // es usado por los metodos que usan calculos
	int numeroD = 0; // es usado por los metodos que usan calculos
	int numEspI = 0; // es usado por los metodos que usan calculos
	int numEspD = 0; // es usado por los metodos que usan calculos
	int horizontalTransferRate;
	boolean verFrontera = false;
	boolean viewMaleFemale = false;
	boolean parar = false;
	boolean collectWidth = false;
	boolean collectHeight = false;
	boolean collectSpeed = false;
	boolean collectColor = false;
	boolean collectSense = false;
	boolean collectPredator = false;
	boolean collectHunt = false;
	boolean collectEscape = false;
	boolean collectRadius = false;
	boolean collectMutationRate = false;
	boolean collectLongevity = false;
	boolean collectTemp = false;
	boolean collectResistance = false;
	boolean collectPheromone = false;
	boolean colectarParteNoGen = false;
	boolean mutarColor = true;
	boolean mutarSize = true;
	boolean mutarSpeed = true;
	boolean mutarSentir = true;
	boolean mutarPredador = true;
	boolean mutarCazar = true;
	boolean mutarEscapar = true;
	boolean mutarRadioconsiente = true;
	boolean mutarTasaMut = true;
	boolean mutarLongevidad = true;
	boolean mutarTemp = true;
	boolean mutarResistencia = true;
	boolean mutarFeromona = false;
	boolean mutarParteNoGen = false;
	boolean cargarPoblacion = false;
	boolean moverMasa;
	String ruta, poblacion;
	StringBuffer linea, orgNombre; // se usa para archivar los resultado
	StringBuffer ceroIz, ceroIz2; // agrega un cero a la izquierda
	String nombre;
	TextureAtlas textuRA_ENER, textura_ORG, organismTexture, textura_sex; // contine
	// las
	// imagenes
	Texture auraATB, transferido, textura_feromona;
	Archive f_datos, f_genes, f_arbol, f_proteoma, f_poblacion, f_mutantes,
			f_alelos, f_fenotipos, f_genotipos, f_alelos2; // para archivar
	NumberFormat format = new DecimalFormat("0.00");
	NumberFormat format2 = new DecimalFormat("0");
	NumberFormat format3 = new DecimalFormat("#.##");
	Rectangle frontera;
	public World(Evoluzion ev, String ruta, String nombre, String poblacion,
				 int numOrg, int numSen, int numQen, int Senergia, int Qbiomasa,
				 int numSenR, int numQenR, int SenergiaR, int QbiomasaR,
				 boolean cargarPoblacion, boolean moverMasa, boolean verFrontera,
				 boolean viewMaleFemale, String genesPedidos, int ingles) {
		this.ev = ev;
		this.numOrg = numOrg;
		this.numSen = numSen;
		this.numQen = numQen;
		this.Senergia = Senergia;
		this.Qbiomasa = Qbiomasa;
		this.numSenR = numSenR;
		this.numQenR = numQenR;
		this.SenergiaR = SenergiaR;
		this.QbiomasaR = QbiomasaR;
		this.cargarPoblacion = cargarPoblacion;
		this.moverMasa = moverMasa;
		this.verFrontera = verFrontera;
		this.viewMaleFemale = viewMaleFemale;
		this.nombre = nombre;
		this.ruta = ruta;
		this.poblacion = poblacion;
		this.ingles = ingles;
		tx = new Text();
		if (ingles == 1) {
			tx.setEnglish();
		}
		if (ingles == -1) {
			tx.setSpanish();
		}
		orgNombre = new StringBuffer("a");
		ceroIz = new StringBuffer();
		ceroIz2 = new StringBuffer();
		// quaddtree
		// quad = new Quadtree(0, new Rectangle(0,0,ancho,alto));
		// tamaño de la pantalla
		ancho = Gdx.graphics.getWidth();
		alto = Gdx.graphics.getHeight();
		// listas
		ase = new Array();
		ase1 = new Array();
		ase2 = new Array();
		ase3 = new Array();
		ase4 = new Array();
		ase5 = new Array();
		ase6 = new Array();
		ase7 = new Array();
		ase8 = new Array();
		ase9 = new Array();
		ase10 = new Array();
		aqe = new Array();
		aqe1 = new Array();
		aqe2 = new Array();
		aqe3 = new Array();
		aqe4 = new Array();
		aqe5 = new Array();
		aqe6 = new Array();
		aqe7 = new Array();
		aqe8 = new Array();
		aqe9 = new Array();
		aqe10 = new Array();
		organisms = new Array();
		aEspesies = new Array();
		aEspesiesTotales = new Array();
		aAlelos = new Array();
		aFenotipos = new Array();
		aGenotipos = new Array();
		// set time to 0
		setDelta();
		setDelta2();
		setDelta3();
		setTiempo();
		linea = new StringBuffer();// used to write text in files
		organismTexture = new TextureAtlas("data/organismo.pack");
		frontera = new Rectangle();
		frontera.x = (ancho / 2) - 10;
		frontera.y = 0;
		frontera.height = alto;
		frontera.width = 20;
		// agregar cuantos de energia solar panel Izquierdo
		float x = 0;
		float y = alto;
		for (int i = 0; i < this.numSen; i++) {
			Vector2 pos = new Vector2((float) Math.random() * ancho / 2,
					(float) Math.random() * alto);
			x = x + 20;
			if (x >= ancho) {
				x = 0;
				y = y - 20;
			}
			Senergy se = new Senergy(pos, this);
			se.energy = this.Senergia;
			ase.add(se);
		}
		// agregar cuantos de energia solar panel Derecho
		for (int e = 0; e < this.numSenR; e++) {
			Vector2 pos = new Vector2((float) Math.random()
					* (ancho - (ancho / 2)) + ancho / 2, (float) Math.random()
					* alto);
			x = x + 20;
			if (x >= ancho) {
				x = 0;
				y = y - 20;
			}
			Senergy se = new Senergy(pos, this);
			se.energy = this.SenergiaR;
			ase.add(se);
		}
		ase.shuffle();
		ase.shrink();
		// agregar cuantos de energia en las listas divididas por sector
		for (int i = 0; i < ase.size; i++) {
			if (ase.get(i).posicion.x <= ancho * (1 / 10)) {
				ase1.add(ase.get(i));
			}
			if (ase.get(i).posicion.x > ancho * (1 / 10)
					&& ase.get(i).posicion.x <= ancho * (2 / 10)) {
				ase2.add(ase.get(i));
			}
			if (ase.get(i).posicion.x > ancho * (2 / 10)
					&& ase.get(i).posicion.x <= ancho * (3 / 10)) {
				ase3.add(ase.get(i));
			}
			if (ase.get(i).posicion.x > ancho * (3 / 10)
					&& ase.get(i).posicion.x <= ancho * (4 / 10)) {
				ase4.add(ase.get(i));
			}
			if (ase.get(i).posicion.x > ancho * (4 / 10)
					&& ase.get(i).posicion.x <= ancho * (5 / 10)) {
				ase5.add(ase.get(i));
			}
			if (ase.get(i).posicion.x > ancho * (5 / 10)
					&& ase.get(i).posicion.x <= ancho * (6 / 10)) {
				ase6.add(ase.get(i));
			}
			if (ase.get(i).posicion.x > ancho * (6 / 10)
					&& ase.get(i).posicion.x <= ancho * (7 / 10)) {
				ase7.add(ase.get(i));
			}
			if (ase.get(i).posicion.x > ancho * (7 / 10)
					&& ase.get(i).posicion.x <= ancho * (8 / 10)) {
				ase8.add(ase.get(i));
			}
			if (ase.get(i).posicion.x > ancho * (8 / 10)
					&& ase.get(i).posicion.x <= ancho * (9 / 10)) {
				ase9.add(ase.get(i));
			}
			if (ase.get(i).posicion.x > ancho * (9 / 10)
					&& ase.get(i).posicion.x <= ancho) {
				ase10.add(ase.get(i));
			}
		}
		ase1.shrink();// ajusta el tamaño de la lista a la cantedidad de
						// elmentos que tiene
		ase2.shrink();
		ase3.shrink();
		ase4.shrink();
		ase5.shrink();
		ase6.shrink();
		ase7.shrink();
		ase8.shrink();
		ase9.shrink();
		ase10.shrink();
		// agregar materia del lado izquierdo
		for (int i = 0; i < this.numQen; i++) {
			Vector2 pos = new Vector2((float) Math.random() * ancho / 2,
					(float) Math.random() * alto);
			aqe.add(new Qenergy(pos, moverMasa, Qbiomasa, this));
		}
		// agregar materia del lado Derecho
		for (int i = 0; i < this.numQenR; i++) {
			Vector2 pos = new Vector2((float) Math.random()
					* (ancho - (ancho / 2)) + ancho / 2, (float) Math.random()
					* alto);
			aqe.add(new Qenergy(pos, moverMasa, this.QbiomasaR, this));
		}
		// agregar materia invisible para usarla en el balanse de masa
		for (int i = 0; i < numQen / 3; i++) {
			Vector2 pos = new Vector2((float) Math.random() * ancho / 2,
					(float) Math.random() * alto);
			Qenergy qe = new Qenergy(pos, moverMasa, Qbiomasa, this);
			qe.visible = false;
			aqe.add(qe);
		}
		for (int i = 0; i < this.numQenR / 3; i++) {
			Vector2 pos = new Vector2((float) Math.random()
					* (ancho - (ancho / 2)) + ancho / 2, (float) Math.random()
					* alto);
			Qenergy qe = new Qenergy(pos, moverMasa, QbiomasaR, this);
			qe.visible = false;
			aqe.add(qe);
		}
		aqe.shrink();
		// repartirla materia izquierda y derecha
		// agregar cuantos de materia en las listas divididas por sector
		for (int i = 0; i < aqe.size; i++) {
			if (aqe.get(i).position.x <= ancho * (1 / 10)) {
				aqe1.add(aqe.get(i));
			}
			if (aqe.get(i).position.x > ancho * (1 / 10)
					&& aqe.get(i).position.x <= ancho * (2 / 10)) {
				aqe2.add(aqe.get(i));
			}
			if (aqe.get(i).position.x > ancho * (2 / 10)
					&& aqe.get(i).position.x <= ancho * (3 / 10)) {
				aqe3.add(aqe.get(i));
			}
			if (aqe.get(i).position.x > ancho * (3 / 10)
					&& aqe.get(i).position.x <= ancho * (4 / 10)) {
				aqe4.add(aqe.get(i));
			}
			if (aqe.get(i).position.x > ancho * (4 / 10)
					&& aqe.get(i).position.x <= ancho * (5 / 10)) {
				aqe5.add(aqe.get(i));
			}
			if (aqe.get(i).position.x > ancho * (5 / 10)
					&& aqe.get(i).position.x <= ancho * (6 / 10)) {
				aqe6.add(aqe.get(i));
			}
			if (aqe.get(i).position.x > ancho * (6 / 10)
					&& aqe.get(i).position.x <= ancho * (7 / 10)) {
				aqe7.add(aqe.get(i));
			}
			if (aqe.get(i).position.x > ancho * (7 / 10)
					&& aqe.get(i).position.x <= ancho * (8 / 10)) {
				aqe8.add(aqe.get(i));
			}
			if (aqe.get(i).position.x > ancho * (8 / 10)
					&& aqe.get(i).position.x <= ancho * (9 / 10)) {
				aqe9.add(aqe.get(i));
			}
			if (aqe.get(i).position.x > ancho * (9 / 10)
					&& aqe.get(i).position.x <= ancho) {
				aqe10.add(aqe.get(i));
			}
		}
		aqe1.shrink();
		aqe2.shrink();
		aqe3.shrink();
		aqe4.shrink();
		aqe5.shrink();
		aqe6.shrink();
		aqe7.shrink();
		aqe8.shrink();
		aqe9.shrink();
		aqe10.shrink();
		// colecta la primera especie en la lista
		for (Organism or : organisms) {
			boolean igual = false;
			id = or.identifier;
			for (Organism or2 : aEspesies) {
				if (id == or2.identifier) {
					igual = true;
				}
			}
			if (igual == false) {
				aEspesies.add(or);
			}
		}
		for (Organism or : organisms) {
			boolean igual = false;
			id = or.identifier;
			for (Organism or2 : aEspesiesTotales) {
				if (id == or2.identifier) {
					igual = true;
				}
			}
			if (igual == false) {
				aEspesiesTotales.add(or);
			}
		}
		// manejamos los archivos
		f_datos = new Archive();
		f_genes = new Archive();
		f_proteoma = new Archive();
		f_arbol = new Archive();
		f_poblacion = new Archive();
		f_mutantes = new Archive();
		f_alelos = new Archive();
		f_fenotipos = new Archive();
		f_genotipos = new Archive();
		f_alelos2 = new Archive();
	}
	// end of cronstructor metod
	// metodos
	public void agregarPrimerosOrg(int pan, boolean sex, int num, int tosRes,
			int anch, int alt, int senses, int optTem, int pred, int speed,
			int cazar, int escape, int radio, int fer, int parteNoGen,
			int relleno, int dnaPol, int longe, int col) {
		for (int i = 0; i < num; i++) {
			float a = 0;
			if (pan == 1) {
				a = (float) Math.random() * (ancho - (ancho / 2)) + ancho / 2;
			}
			if (pan == 2) {
				a = (float) Math.random() * ancho / 2;
			}
			Vector2 pos = new Vector2(a, (float) Math.random() * alto);
			Vector2 dir = new Vector2((float) Math.random() * 20,
					(float) Math.random() * 20);
			if (dir.x < 10) {
				dir.x = dir.x * (-1);
			}
			if (dir.x > 10) {
				dir.x = dir.x - 10;
			}
			if (dir.y < 10) {
				dir.y = dir.y * (-1);
			}
			if (dir.y > 10) {
				dir.y = dir.y - 10;
			}
			Organism or = new Organism(sex, new Genome(this, tosRes, anch,
					alt, senses, optTem, pred), new Genome(this, tosRes, anch,
					alt, senses, optTem, pred), new Genome(this, speed, cazar,
					escape, radio, fer, parteNoGen, relleno), new Genome(this,
					speed, cazar, escape, radio, fer, parteNoGen, relleno),
					new Genome(this, dnaPol, longe, col), new Genome(this,
					dnaPol, longe, col), pos, orgNombre, this);
			or.direction = dir;
			or.infected = true;
			organisms.add(or);
		}
		double o = BiomasaTotal(organisms) / Qbiomasa;
		for (int i = 0; i < o; i++) {
			Qenergy qe = aqe.get(i);
			qe.visible = false;
		}
		Masatotal = MateriaLibre() + BiomasaTotal(organisms);
		MasatotalL = MateriaLibreL() + BiomasaTotalI(organisms);
		MasatotalR = MateriaLibreR() + BiomasaTotalD(organisms);
		cantidadOrganismosI(organisms);
		cantidadOrganismosD(organisms);
		cantidadEspeciesI(organisms);
		cantidadEspeciesD(organisms);
	}
	public int cantidadOrganismos(Array aor) {
		return aor.size;
	}
	public void cantidadOrganismosI(Array aor) {
		int num = 0;
		for (int i = 0; i < aor.size; i++) {
			if (aor.get(i).position.x < ancho / 2) {
				num = num + 1;
			}
			//	System.out.println("dentro del loop"+ num);//return numeroI;
		}
		numeroI = num;
		//System.out.println("dentro del metodo"+ numeroI);//return numeroI;
	}
	//caluculos
	public void cantidadOrganismosD(Array aor) {
		int num = 0;
		for (int i = 0; i < aor.size; i++) {
			if (aor.get(i).position.x > ancho / 2) {
				num = num + 1;
			}
		}
		numeroD = num;
		//return numeroD;
	}
	public void cantidadEspeciesI(Array aor) {
		int num = 0;
		for (int i = 0; i < aor.size; i++) {
			if (aor.get(i).position.x > ancho / 2) {
				num = num + 1;
			}
		}
		numEspI = num;
		//return numeroD;
	}
	public void cantidadEspeciesD(Array aor) {
		int num = 0;
		for (int i = 0; i < aor.size; i++) {
			if (aor.get(i).position.x > ancho / 2) {
				num = num + 1;
			}
		}
		numEspD = num;
		//return numeroD;
	}
	public void borrarOrganismo(Organism or) {
		organisms.removeValue(or, true);
		or = null;
		organisms.shrink();
	}
	// cuenta la cantidad de machos
	public int cantidadMachos(Array aor) {
		numero = aor.size;
		int machos = 0;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).male == true) {
				machos = machos + 1;
			}
		}
		return machos;
	}
	public int cantidadMachosI(Array aor) {
		numero = aor.size;
		int machos = 0;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).position.x < ancho / 2 && aor.get(i).male == true) {
				machos = machos + 1;
			}
		}
		return machos;
	}
	public int cantidadMachosD(Array aor) {
		numero = aor.size;
		int machos = 0;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).position.x > ancho / 2 && aor.get(i).male == true) {
				machos = machos + 1;
			}
		}
		return machos;
	}
	public int cantidadHembras(Array aor) {
		numero = aor.size;
		int hembras = 0;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).male == false) {
				hembras = hembras + 1;
			}
		}
		return hembras;
	}
	public int cantidadHembrasI(Array aor) {
		numero = aor.size;
		int hembras = 0;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).position.x < ancho / 2 && aor.get(i).male == false) {
				hembras = hembras + 1;
			}
		}
		return hembras;
	}
	public int cantidadHembrasD(Array aor) {
		numero = aor.size;
		int hembras = 0;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).position.x > ancho / 2 && aor.get(i).male == false) {
				hembras = hembras + 1;
			}
		}
		return hembras;
	}
	public double temOptimaMedia(Array aor) {
		medTem = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				medTem = medTem + aor.get(i).optimalTemp;
			}
		}
		if (numero == 0) {
			numero = 1;
		}
		return medTem / numero;
	}
	public double temOptimaMediaI(Array aor) {
		medTem = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				if (aor.get(i).position.x < ancho / 2) {
					medTem = medTem + aor.get(i).optimalTemp;
				}
			}
		}
		if (numero == 0) {
			numero = 1;
		}
		return medTem / numeroI;
	}
	public double temOptimaMediaD(Array aor) {
		medTem = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				if (aor.get(i).position.x > ancho / 2) {
					medTem = medTem + aor.get(i).optimalTemp;
				}
			}
		}
		if (numero == 0) {
			numero = 1;
		}
		return medTem / numeroD;
	}
	public int cantidadPredadores(Array aor) {
		cantidad = 0;
		numero = aor.size;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).carnivore == true) {
				cantidad = cantidad + 1;
			}
		}
		return cantidad;
	}
	public int cantidadPredadoresI(Array aor) {
		cantidad = 0;
		numero = aor.size;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).position.x < ancho / 2
					&& aor.get(i).carnivore == true) {
				cantidad = cantidad + 1;
			}
		}
		return cantidad;
	}
	public int cantidadPredadoresD(Array aor) {
		cantidad = 0;
		numero = aor.size;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).position.x > ancho / 2
					&& aor.get(i).carnivore == true) {
				cantidad = cantidad + 1;
			}
		}
		return cantidad;
	}
	public int cantidadResistentes(Array aor) {
		cantidad = 0;
		numero = aor.size;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).resistanceATB == true) {
				cantidad = cantidad + 1;
			}
		}
		return cantidad;
	}
	public int cantidadResistentesI(Array aor) {
		cantidad = 0;
		numero = aor.size;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).position.x < ancho / 2
					&& aor.get(i).resistanceATB == true) {
				cantidad = cantidad + 1;
			}
		}
		return cantidad;
	}
	public int cantidadResistentesD(Array aor) {
		cantidad = 0;
		numero = aor.size;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).position.x > ancho / 2
					&& aor.get(i).resistanceATB == true) {
				cantidad = cantidad + 1;
			}
		}
		return cantidad;
	}
	public float velocidadMedia(Array aor) {
		medSpeed = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				medSpeed = medSpeed + aor.get(i).speed;
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return medSpeed / numero;
	}
	public float velocidadMediaI(Array aor) {
		medSpeed = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				if (aor.get(i).position.x < ancho / 2) {
					medSpeed = medSpeed + aor.get(i).speed;
				}
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return medSpeed / numeroI;
	}
	public float velocidadMediaD(Array aor) {
		medSpeed = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				if (aor.get(i).position.x > ancho / 2) {
					medSpeed = medSpeed + aor.get(i).speed;
				}
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return medSpeed / numeroD;
	}
	public int tasaMutMedio(Array aor) {
		medMut = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				medMut = (int) (medMut + aor.get(i).mutationRate);
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return (medMut / numero);
	}
	public int tasaMutMedioI(Array aor) {
		medMut = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				if (aor.get(i).position.x < ancho / 2) {
					medMut = (int) (medMut + aor.get(i).mutationRate);
				}
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return (medMut / numeroI);
	}
	public int tasaMutMedioD(Array aor) {
		medMut = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				if (aor.get(i).position.x > ancho / 2) {
					medMut = (int) (medMut + aor.get(i).mutationRate);
				}
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return (medMut / numeroD);
	}
	public float longevidadMedio(Array aor) {
		medLon = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				medLon = (int) (medLon + aor.get(i).longevity);
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return (float) (medLon) / 1000 / numero;
	}
	public float longevidadMedioI(Array aor) {
		medLon = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				if (aor.get(i).position.x < ancho / 2) {
					medLon = (int) (medLon + aor.get(i).longevity);
				}
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return (float) (medLon) / 1000 / numeroI;
	}
	public float longevidadMedioD(Array aor) {
		medLon = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				if (aor.get(i).position.x > ancho / 2) {
					medLon = (int) (medLon + aor.get(i).longevity);
				}
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return (float) (medLon) / 1000 / numeroD;
	}
	public float saludMedio(Array aor) {
		salud = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				salud = salud + aor.get(i).SaludCoefi;
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return salud / numero;
	}
	public float saludMedioD(Array aor) {
		salud = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				if (aor.get(i).position.x > ancho / 2) {
					salud = salud + aor.get(i).SaludCoefi;
				}
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return salud / numeroD;
	}
	public float saludMedioI(Array aor) {
		salud = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				if (aor.get(i).position.x < ancho / 2) {
					salud = salud + aor.get(i).SaludCoefi;
				}
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return salud / numeroI;
	}
	public float tamanoMedio(Array aor) {
		medSize = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				medSize = medSize + aor.get(i).capacity;
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return medSize / numero;
	}
	public float tamanoMedioI(Array aor) {
		medSize = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				if (aor.get(i).position.x < ancho / 2) {
					medSize = medSize + aor.get(i).capacity;
				}
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return medSize / numeroI;
	}
	public float tamanoMedioD(Array aor) {
		medSize = 0;
		numero = aor.size;
		if (numero > 0) {
			for (int i = numero - 1; i >= 0; i--) {
				if (aor.get(i).position.x > ancho / 2) {
					medSize = medSize + aor.get(i).capacity;
				}
			}
		}
		if (numero == 0 || numeroI == 0 || numeroD == 0) {
			numero = 1;
			numeroI = 1;
			numeroD = 1;
		}
		return medSize / numeroD;
	}
	public int MateriaLibre() {
		int materia = 0;
		numero = aqe.size;
		for (int i = numero - 1; i >= 0; i--) {
			if (aqe.get(i).visible == true) {
				materia = (int) (materia + aqe.get(i).mass);
			}
		}
		return materia;
	}
	public int MateriaLibreL() {
		int materia = 0;
		numero = aqe.size;
		for (int i = numero - 1; i >= 0; i--) {
			if (aqe.get(i).position.x < ancho / 2 && aqe.get(i).visible == true) {
				materia = (int) (materia + aqe.get(i).mass);
			}
		}
		return materia;
	}
	public int MateriaLibreR() {
		int materia = 0;
		numero = aqe.size;
		for (int i = numero - 1; i >= 0; i--) {
			if (aqe.get(i).position.x > ancho / 2 && aqe.get(i).visible == true) {
				materia = (int) (materia + aqe.get(i).mass);
			}
		}
		return materia;
	}
	public double BiomasaTotal(Array aor) {
		int biomasaTotal = 0;
		numero = aor.size;
		for (int i = numero - 1; i >= 0; i--) {
			biomasaTotal = (int) (biomasaTotal + aor.get(i).biomass);
		}
		return biomasaTotal;
	}
	public int BiomasaTotalD(Array aor) {
		int biomasaTotal = 0;
		numero = aor.size;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).position.x > ancho / 2) {
				biomasaTotal = (int) (biomasaTotal + aor.get(i).biomass);
			}
		}
		return biomasaTotal;
	}
	public int BiomasaTotalI(Array aor) {
		int biomasaTotal = 0;
		numero = aor.size;
		for (int i = numero - 1; i >= 0; i--) {
			if (aor.get(i).position.x < ancho / 2) {
				biomasaTotal = (int) (biomasaTotal + aor.get(i).biomass);
			}
		}
		return biomasaTotal;
	}
	public int BioenergiaTotal(Array aor) {
		int energiaTotal = 0;
		numero = aor.size;
		for (int i = numero - 1; i >= 0; i--) {
			energiaTotal = (int) (energiaTotal + aor.get(i).energy);
		}
		return energiaTotal;
	}
	// to correct rounding errors in the total mass of the system, add or remove
	// mass
	public void chequearBalance() {
		if (verFrontera == false) {
			double a = Masatotal - (MateriaLibre() + BiomasaTotal(organisms));
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			a = Masatotal - (MateriaLibre() + BiomasaTotal(organisms));
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			a = Masatotal - (MateriaLibre() + BiomasaTotal(organisms));
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			a = Masatotal - (MateriaLibre() + BiomasaTotal(organisms));
			if (a < Qbiomasa * (-1)) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == true) {
						aqe.get(i).visible = false;
						i = 0;
					}
				}
			}
			if (a < Qbiomasa * (-1)) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == true) {
						aqe.get(i).visible = false;
						i = 0;
					}
				}
			}
			a = Masatotal - (MateriaLibre() + BiomasaTotal(organisms));
			if (a < Qbiomasa * (-1)) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == true) {
						aqe.get(i).visible = false;
						i = 0;
					}
				}
			}
			if (a < Qbiomasa * (-1)) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).visible == true) {
						aqe.get(i).visible = false;
						i = 0;
					}
				}
			}
		}
		if (verFrontera == true) {
			double a = MasatotalL - (MateriaLibreL() + BiomasaTotalI(organisms));
			numero = 0;
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			a = MasatotalL - (MateriaLibreL() + BiomasaTotalI(organisms));
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			a = MasatotalL - (MateriaLibreL() + BiomasaTotalI(organisms));
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (a > Qbiomasa) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			a = MasatotalL - (MateriaLibreL() + BiomasaTotalI(organisms));
			if (a < Qbiomasa * (-1)) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == true) {
						aqe.get(i).visible = false;
						i = 0;
					}
				}
			}
			if (a < Qbiomasa * (-1)) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == true) {
						aqe.get(i).visible = false;
						i = 0;
					}
				}
			}
			a = MasatotalL - (MateriaLibreL() + BiomasaTotalI(organisms));
			if (a < Qbiomasa * (-1)) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == true) {
						aqe.get(i).visible = false;
						i = 0;
					}
				}
			}
			if (a < Qbiomasa * (-1)) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x < ancho / 2
							&& aqe.get(i).visible == true) {
						aqe.get(i).visible = false;
						i = 0;
					}
				}
			}
			// lado derecho
			double b = MasatotalR - (MateriaLibreR() + BiomasaTotalD(organisms));
			if (b > QbiomasaR) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (b > QbiomasaR) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (b > QbiomasaR) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			b = MasatotalR - (MateriaLibreR() + BiomasaTotalD(organisms));
			if (b > QbiomasaR) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (b > QbiomasaR) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (b > QbiomasaR) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			b = MasatotalR - (MateriaLibreR() + BiomasaTotalD(organisms));
			if (b > QbiomasaR) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (b > QbiomasaR) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			if (b > QbiomasaR) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == false) {
						aqe.get(i).visible = true;
						i = 0;
					}
				}
			}
			b = MasatotalR - (MateriaLibreR() + BiomasaTotalD(organisms));
			if (b < QbiomasaR * (-1)) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == true) {
						aqe.get(i).visible = false;
						i = 0;
					}
				}
			}
			if (b < QbiomasaR * (-1)) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == true) {
						aqe.get(i).visible = false;
						i = 0;
					}
				}
			}
			b = MasatotalR - (MateriaLibreR() + BiomasaTotalD(organisms));
			if (b < QbiomasaR * (-1)) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == true) {
						aqe.get(i).visible = false;
						i = 0;
					}
				}
			}
			if (b < QbiomasaR * (-1)) {
				numero = aqe.size;
				for (int i = numero - 1; i >= 0; i--) {
					if (aqe.get(i).position.x > ancho / 2
							&& aqe.get(i).visible == true) {
						aqe.get(i).visible = false;
						i = 0;
					}
				}
			}
		}
	}
	// kill 95% of all organism
	public void catastrofe() {
		numero = organisms.size;
		for (int i = numero - 1; i >= 0; i--) {
			int e = (int) (Math.random() * 10000);
			if (e > 500) {
				organisms.get(i).morir();
			}
		}
	}
	// metodos para colectar los datos
	public void guardarPoblacion() {
		try {
			JFileChooser fc = new JFileChooser();
			fc.setCurrentDirectory(new File(ruta));
			FileNameExtensionFilter filter = new FileNameExtensionFilter(
					"población Total" + "     (pob2)", "pob2");
			fc.setFileFilter(filter);
			int returnVal = fc.showSaveDialog(fc);
			if (fc.getFileFilter() == filter) {
				if (returnVal == JFileChooser.APPROVE_OPTION) {
					// File file = fc.getSelectedFile();
					f_poblacion.createArchive(fc.getSelectedFile() + ".pob2");
					StringBuffer linea = new StringBuffer();
					numero = organisms.size;
					for (int i = numero - 1; i >= 0; i--) {
						Organism or = organisms.get(i);
						linea.replace(0, linea.length(), "" + or.male
								+ "" + or.nombre.toString() + "dX"
								+ or.position.x + "dY" + or.position.y
								+ "" + or.adn.resistanceATB + ""
								+ or.adn.width + "" + or.adn.height
								+ "" + or.adn.sense + ""
								+ or.adn.toleranceTemp + ""
								+ or.adn.predator + "" + or.adn3.speed
								+ "" + or.adn3.hunt + ""
								+ or.adn3.escape + ""
								+ or.adn3.radius + ""
								+ or.adn3.pheromone + ""
								+ or.adn3.parteNoGen + ""
								+ or.adn5.mutationRate + ""
								+ or.adn5.longevity + ""
								+ or.adn5.color + ""
								+ or.adn2.resistanceATB + ""
								+ or.adn2.width + "" + or.adn2.height
								+ "" + or.adn2.sense + ""
								+ or.adn2.toleranceTemp + ""
								+ or.adn2.predator + "" + or.adn4.speed
								+ "" + or.adn4.hunt + ""
								+ or.adn4.escape + ""
								+ or.adn4.radius + ""
								+ or.adn4.pheromone + ""
								+ or.adn4.parteNoGen + ""
								+ or.adn6.mutationRate + ""
								+ or.adn6.longevity + ""
								+ or.adn6.color + "\n");
						f_poblacion.writeArchive(linea.toString());
					}
					f_poblacion.cerrarArchivo();
				}
			}
		} catch (HeadlessException e) {
			JOptionPane.showMessageDialog(null, "error al escribir el archivo");
			e.printStackTrace();
		}
	}
	public void guardarPoblacionMarcada() {
		try {
			JFileChooser fc = new JFileChooser();
			fc.setCurrentDirectory(new File(ruta));
			FileNameExtensionFilter filter = new FileNameExtensionFilter(
					"población Marcada" + "     (pob2)", "pob2");
			fc.setFileFilter(filter);
			int returnVal = fc.showSaveDialog(fc);
			if (fc.getFileFilter() == filter) {
				if (returnVal == JFileChooser.APPROVE_OPTION) {
					// File file = fc.getSelectedFile();
					f_poblacion.createArchive(fc.getSelectedFile() + ".pob2");
					StringBuffer linea = new StringBuffer();
					numero = organisms.size;
					for (int i = numero - 1; i >= 0; i--) {
						Organism or = organisms.get(i);
						if (or.mark == -1) { // -1 == true
							linea.replace(0, linea.length(), "" + or.male
									+ "" + or.nombre.toString() + "dX"
									+ or.position.x + "dY" + or.position.y
									+ "" + or.adn.resistanceATB
									+ "" + or.adn.width + ""
									+ or.adn.height + "" + or.adn.sense
									+ "" + or.adn.toleranceTemp
									+ "" + or.adn.predator
									+ "" + or.adn3.speed + ""
									+ or.adn3.hunt + ""
									+ or.adn3.escape + ""
									+ or.adn3.radius + ""
									+ or.adn3.pheromone + ""
									+ or.adn3.parteNoGen + ""
									+ or.adn5.mutationRate + ""
									+ or.adn5.longevity + ""
									+ or.adn5.color + ""
									+ or.adn2.resistanceATB + ""
									+ or.adn2.width + "" + or.adn2.height
									+ "" + or.adn2.sense + ""
									+ or.adn2.toleranceTemp + ""
									+ or.adn2.predator + ""
									+ or.adn4.speed + ""
									+ or.adn4.hunt + ""
									+ or.adn4.escape + ""
									+ or.adn4.radius + ""
									+ or.adn4.pheromone + ""
									+ or.adn4.parteNoGen + ""
									+ or.adn6.mutationRate + ""
									+ or.adn6.longevity + ""
									+ or.adn6.color + "\n");
							f_poblacion.writeArchive(linea.toString());
						}
					}
					f_poblacion.cerrarArchivo();
				}
			}
		} catch (HeadlessException e) {
			JOptionPane.showMessageDialog(null, "error al escribir el archivo");
			e.printStackTrace();
		}
	}
	public void guardarPoblacionNoMaracada() {
		try {
			JFileChooser fc = new JFileChooser();
			fc.setCurrentDirectory(new File(ruta));
			FileNameExtensionFilter filter = new FileNameExtensionFilter(
					"población No Marcada" + "     (pob2)", "pob2");
			fc.setFileFilter(filter);
			int returnVal = fc.showSaveDialog(fc);
			if (fc.getFileFilter() == filter) {
				if (returnVal == JFileChooser.APPROVE_OPTION) {
					// File file = fc.getSelectedFile();
					f_poblacion.createArchive(fc.getSelectedFile() + ".pob2");
					StringBuffer linea = new StringBuffer();
					numero = organisms.size;
					for (int i = numero - 1; i >= 0; i--) {
						Organism or = organisms.get(i);
						if (or.mark == 1) { // 1 = false
							linea.replace(0, linea.length(), "" + or.male
									+ "" + or.nombre.toString() + "dX"
									+ or.position.x + "dY" + or.position.y
									+ "" + or.adn.resistanceATB
									+ "" + or.adn.width + ""
									+ or.adn.height + "" + or.adn.sense
									+ "" + or.adn.toleranceTemp
									+ "" + or.adn.predator
									+ "" + or.adn3.speed + ""
									+ or.adn3.hunt + ""
									+ or.adn3.escape + ""
									+ or.adn3.radius + ""
									+ or.adn3.pheromone + ""
									+ or.adn3.parteNoGen + ""
									+ or.adn5.mutationRate + ""
									+ or.adn5.longevity + ""
									+ or.adn5.color + ""
									+ or.adn2.resistanceATB + ""
									+ or.adn2.width + "" + or.adn2.height
									+ "" + or.adn2.sense + ""
									+ or.adn2.toleranceTemp + ""
									+ or.adn2.predator + ""
									+ or.adn4.speed + ""
									+ or.adn4.hunt + ""
									+ or.adn4.escape + ""
									+ or.adn4.radius + ""
									+ or.adn4.pheromone + ""
									+ or.adn4.parteNoGen + ""
									+ or.adn6.mutationRate + ""
									+ or.adn6.longevity + ""
									+ or.adn6.color + "\n");
							f_poblacion.writeArchive(linea.toString());
						}
					}
					f_poblacion.cerrarArchivo();
				}
			}
		} catch (HeadlessException e) {
			JOptionPane.showMessageDialog(null, "error al escribir el archivo");
			e.printStackTrace();
		}
	}
	public void leerArchivoPoblacion() {
		for (Organism or : organisms) {
			organisms.removeValue(or, true);
		}
		for (Organism or : aEspesiesTotales) {
			aEspesiesTotales.removeValue(or, true);
		}
		try {
			FileReader fr = new FileReader(poblacion);
			BufferedReader br = new BufferedReader(fr);
			String linea = null;
			while ((linea = br.readLine()) != null) {
				Genome gen = new Genome(this, 1, 1, 1, 0, 0, 0);
				Genome gen2 = new Genome(this, 1, 1, 1, 0, 0, 0);
				Genome gen3 = new Genome(this, 0, 0, 0, 0, 0, 0, 0);
				Genome gen4 = new Genome(this, 0, 0, 0, 0, 0, 0, 0);
				Genome gen5 = new Genome(this, 0, 0, 0);
				Genome gen6 = new Genome(this, 0, 0, 0);
				StringBuffer sexo = new StringBuffer(linea.substring(
						linea.indexOf("") + 6, linea.indexOf("")));
				StringBuffer nombre = new StringBuffer(linea.substring(
						linea.indexOf("") + 3, linea.indexOf("dX")));
				Vector2 pos = new Vector2(
						Float.parseFloat(linea.substring(
								linea.indexOf("dX") + 2, linea.indexOf("dY"))),
						Float.parseFloat(linea.substring(
								linea.indexOf("dY") + 2, linea.indexOf(""))));
				boolean male = true;
				if (sexo.toString().equals("true")) {
					male = true;
				}
				if (sexo.toString().equals("false")) {
					male = false;
				}
				gen.resistanceATB.replace(
						0,
						gen.resistanceATB.length(),
						linea.substring(linea.indexOf("") + 5,
								linea.indexOf("")));
				gen.width.replace(
						0,
						gen.width.length(),
						linea.substring(linea.indexOf("") + 7,
								linea.indexOf("")));
				gen.height.replace(
						0,
						gen.height.length(),
						linea.substring(linea.indexOf("") + 6,
								linea.indexOf("")));
				gen.sense.replace(
						0,
						gen.sense.length(),
						linea.substring(linea.indexOf("") + 8,
								linea.indexOf("")));
				gen.toleranceTemp.replace(
						0,
						gen.toleranceTemp.length(),
						linea.substring(linea.indexOf("") + 6,
								linea.indexOf("")));
				gen.predator.replace(
						0,
						gen.predator.length(),
						linea.substring(linea.indexOf("") + 10,
								linea.indexOf("")));
				gen3.speed.replace(
						0,
						gen3.speed.length(),
						linea.substring(linea.indexOf("") + 7,
								linea.indexOf("")));
				gen3.hunt.replace(
						0,
						gen3.hunt.length(),
						linea.substring(linea.indexOf("") + 7,
								linea.indexOf("")));
				gen3.escape.replace(
						0,
						gen3.escape.length(),
						linea.substring(linea.indexOf("") + 9,
								linea.indexOf("")));
				gen3.radius.replace(
						0,
						gen3.radius.length(),
						linea.substring(linea.indexOf("") + 9,
								linea.indexOf("")));
				gen3.pheromone.replace(
						0,
						gen3.pheromone.length(),
						linea.substring(linea.indexOf("") + 6,
								linea.indexOf("")));
				gen3.parteNoGen.replace(
						0,
						gen4.parteNoGen.length(),
						linea.substring(linea.indexOf("") + 7,
								linea.indexOf("")));
				gen5.mutationRate.replace(
						0,
						gen5.mutationRate.length(),
						linea.substring(linea.indexOf("") + 9,
								linea.indexOf("")));
				gen5.longevity.replace(0, gen5.longevity.length(), linea
						.substring(linea.indexOf("") + 12,
								linea.indexOf("")));
				gen5.color.replace(
						0,
						gen5.color.length(),
						linea.substring(linea.indexOf("") + 7
						));
				gen2.resistanceATB.replace(
						0,
						gen2.resistanceATB.length(),
						linea.substring(linea.indexOf("") + 6,
								linea.indexOf("")));
				gen2.width.replace(
						0,
						gen2.width.length(),
						linea.substring(linea.indexOf("") + 8,
								linea.indexOf("")));
				gen2.height.replace(
						0,
						gen2.height.length(),
						linea.substring(linea.indexOf("") + 7,
								linea.indexOf("")));
				gen2.sense.replace(
						0,
						gen2.sense.length(),
						linea.substring(linea.indexOf("") + 9,
								linea.indexOf("")));
				gen2.toleranceTemp.replace(
						0,
						gen2.toleranceTemp.length(),
						linea.substring(linea.indexOf("") + 7,
								linea.indexOf("")));
				gen2.predator.replace(0, gen2.predator.length(), linea
						.substring(linea.indexOf("") + 11,
								linea.indexOf("")));
				gen4.speed.replace(
						0,
						gen4.speed.length(),
						linea.substring(linea.indexOf("") + 8,
								linea.indexOf("")));
				gen4.hunt.replace(
						0,
						gen4.hunt.length(),
						linea.substring(linea.indexOf("") + 8,
								linea.indexOf("")));
				gen4.escape.replace(
						0,
						gen4.escape.length(),
						linea.substring(linea.indexOf("") + 10,
								linea.indexOf("")));
				gen4.radius.replace(
						0,
						gen4.radius.length(),
						linea.substring(linea.indexOf("") + 10,
								linea.indexOf("")));
				gen4.pheromone.replace(
						0,
						gen4.pheromone.length(),
						linea.substring(linea.indexOf("") + 7,
								linea.indexOf("")));
				gen4.parteNoGen.replace(
						0,
						gen4.parteNoGen.length(),
						linea.substring(linea.indexOf("") + 8,
								linea.indexOf("")));
				gen6.mutationRate.replace(
						0,
						gen6.mutationRate.length(),
						linea.substring(linea.indexOf("") + 10,
								linea.indexOf("")));
				gen6.longevity.replace(0, gen6.longevity.length(), linea
						.substring(linea.indexOf("") + 11,
								linea.indexOf("")));
				gen6.color.replace(
						0,
						gen6.color.length(),
						linea.substring(linea.indexOf("") + 8
						));
				Organism or = new Organism(male, gen, gen2, gen3, gen4, gen5,
						gen6, pos, nombre, this);
				// asiganr una direccion a cada organismo
				float x = (float) Math.random() * 360;
				float seno = (float) Math.sin(x) * 10;
				float coseno = (float) Math.sin(x + 3.1416 / 2) * 10;
				Vector2 dir = new Vector2(seno, coseno);
				or.direction.x = dir.x;
				or.direction.y = dir.y;
				organisms.add(or);
			}
			Masatotal = MateriaLibre() + BiomasaTotal(organisms);
			MasatotalL = MateriaLibreL() + BiomasaTotalI(organisms);
			MasatotalR = MateriaLibreR() + BiomasaTotalD(organisms);
			br.close();
			fr.close();
		} catch (IOException ex) {
			JOptionPane
					.showMessageDialog(null, "no se puede leer este archivo");
			for (int i = 0; i < numOrg; i++) {
				Vector2 dir = new Vector2((float) Math.random() * 20,
						(float) Math.random() * 20);
				if (dir.x < 10) {
					dir.x = dir.x * (-1);
				}
				if (dir.x > 10) {
					dir.x = dir.x - 10;
				}
				if (dir.y < 10) {
					dir.y = dir.y * (-1);
				}
				if (dir.y > 10) {
					dir.y = dir.y - 10;
				}
				ex.printStackTrace();
			}
		}
	}
	// ordena las los organismos para que se vean mejor al final
	public void Ordenar() {
		if (verFrontera == false) {
			organisms.sort();
			float y = (int) (alto - 120);
			float x = 10;
			for (Organism or : organisms) {
				or.position.x = -100;
				or.position.y = -100;
				or.Ordenar();// este metodo mueve los organismosa un nueva
				// posicion sin usar el metodo update
			}
			for (int e = indice; e < organisms.size; e++) {
				Organism or = organisms.get(e);
				indice++;
				or.position.y = y;
				or.position.x = x;
				x = (int) (x + or.width * 4);
				if (x > ancho - or.width) {
					x = 10;
					y = y - or.height * 6;
				}
				if (y <= 10) {
					e = organisms.size;
				} // si se llena la pantalla de organismos, se detiene el loop
				or.Ordenar();
			}
		}
		if (verFrontera == true) {
			// actualizarListasOrganismos();
			// oreganismos de la derecha
			// lado derecho
			float y = (int) (alto - 120);
			float x = (ancho / 2) + 10;
			for (int e = indiceDer; e < organisms.size; e++) {
				if (organisms.get(e).position.x > ancho / 2) {
					indiceDer++;
					organisms.get(e).position.y = y;
					organisms.get(e).position.x = x;
					x = (int) (x + organisms.get(e).width * 4);
					if (x > ancho - organisms.get(e).width * 4) {
						x = (ancho / 2) + 10;
						y = y - organisms.get(e).height * 6;
					}
					if (y <= 10) {
						e = organisms.size;
					}
				} // si se llena la pantalla de organismos, se detiene el loop
				organisms.get(e).Ordenar();
			}
			// oreganismos de la Izquierda
			float y2 = (int) (alto - 120);
			float x2 = 10;
			for (int e = indiceIz; e < organisms.size; e++) {
				if (organisms.get(e).position.x < ancho / 2) {
					indiceIz++;
					organisms.get(e).position.y = y2;
					organisms.get(e).position.x = x2;
					x2 = (int) (x2 + organisms.get(e).width * 4);
					if (x2 > (ancho / 2) - organisms.get(e).width * 4) {
						x2 = 10;
						y2 = y2 - organisms.get(e).height * 6;
					}
					if (y2 <= 10) {
						e = organisms.size;
					}
				} // si se llena la pantalla de organismos, se detiene el loop
				organisms.get(e).Ordenar();
			}
		}
	}
	// guara las especies que estan en un momento determinado
	// colectar mutantes o especies del momento
	public void colectorEspesies() {
		for (Organism or : aEspesies) {
			or.quantity = 1;
			aEspesies.removeValue(or, true);
		}
		for (Organism or : organisms) {
			boolean igual = false;
			String id = or.nombre.toString();
			for (Organism or2 : aEspesies) {
				if (id.equals(or2.nombre.toString())) {
					igual = true;
					or2.quantity++;
				}
			}
			if (igual == false) {
				aEspesies.add(or);
			}
		}
		aEspesies.sort();
	}
	// colect color allele
	public void colectGenotipo(Array aor, Array agen) {
		if (aor.size > 0) {
			int index = agen.size;
			for (int i = index - 1; i >= 0; i--) {
				agen.get(i).quantity = 1;
				agen.removeValue(agen.get(i), true);
			}
			aor.get(0).genotype.quantity = 0;
			agen.add(aor.get(0).genotype);// agrege el primer alelo
			for (int i = 0; i < aor.size; i++) {
				boolean igual = false;
				for (int j = 0; j < agen.size; j++) {
					if (agen.get(j).name.equals(aor.get(i).genotype.name)) {
						igual = true;
						agen.get(j).quantity++;
					}
				}
				if (igual == false) {
					agen.add(aor.get(i).genotype);
				}
			}
			agen.sort();
		}
	}
	public void colectGenotipoI(Array aor, Array agen) {
		if (aor.size > 0) {
			int index = agen.size;
			for (int i = index - 1; i >= 0; i--) {
				agen.get(i).quantity = 1;
				agen.removeValue(agen.get(i), true);
			}
			int pos = 0;
			for (int i = 0; i < organisms.size; i++) {
				if (organisms.get(i).position.x < ancho / 2) {
					pos = i;
					i = organisms.size;
				}
			}
			aor.get(pos).genotype.quantity = 0;
			agen.add(aor.get(pos).genotype);// agrege el primer alelo
			for (int i = 0; i < aor.size; i++) {
				boolean igual = false;
				if (aor.get(i).position.x < ancho / 2) {
					for (int j = 0; j < agen.size; j++) {
						if (agen.get(j).name
								.equals(aor.get(i).genotype.name)) {
							igual = true;
							agen.get(j).quantity++;
						}
					}
					if (igual == false) {
						agen.add(aor.get(i).genotype);
					}
				}
			}
			agen.sort();
		}
	}
	public void colectGenotipoD(Array aor, Array agen) {
		if (aor.size > 0) {
			int index = agen.size;
			for (int i = index - 1; i >= 0; i--) {
				agen.get(i).quantity = 1;
				agen.removeValue(agen.get(i), true);
			}
			int pos = 0;
			for (int i = 0; i < organisms.size; i++) {
				if (organisms.get(i).position.x > ancho / 2) {
					pos = i;
					i = organisms.size;
				}
			}
			aor.get(pos).genotype.quantity = 0;
			agen.add(aor.get(pos).genotype);// agrege el primer alelo
			for (int i = 0; i < aor.size; i++) {
				boolean igual = false;
				if (aor.get(i).position.x > ancho / 2) {
					for (int j = 0; j < agen.size; j++) {
						if (agen.get(j).name
								.equals(aor.get(i).genotype.name)) {
							igual = true;
							agen.get(j).quantity++;
						}
					}
					if (igual == false) {
						agen.add(aor.get(i).genotype);
					}
				}
			}
			agen.sort();
		}
	}
	public void colectFenotipo(Array aor, Array afen) {
		if (aor.size > 0) {
			int index = afen.size;
			for (int i = index - 1; i >= 0; i--) {
				afen.get(i).quantity = 1;
				afen.removeValue(afen.get(i), true);
			}
			aor.get(0).phenotype.quantity = 0;
			afen.add(aor.get(0).phenotype);// agrege el primer alelo
			for (int i = 0; i < aor.size; i++) {
				boolean igual = false;
				for (int j = 0; j < afen.size; j++) {
					if (afen.get(j).name.equals(aor.get(i).phenotype.name)) {
						igual = true;
						afen.get(j).quantity++;
					}
				}
				if (igual == false) {
					afen.add(aor.get(i).phenotype);
				}
			}
			afen.sort();
		}
	}
	public void colectFenotipoI(Array aor, Array afen) {
		if (aor.size > 0) {
			int index = afen.size;
			for (int i = index - 1; i >= 0; i--) {
				afen.get(i).quantity = 1;
				afen.removeValue(afen.get(i), true);
			}
			int pos = 0;
			for (int i = 0; i < organisms.size; i++) {
				if (organisms.get(i).position.x < ancho / 2) {
					pos = i;
					i = organisms.size;
				}
			}
			aor.get(pos).phenotype.quantity = 0;
			afen.add(aor.get(pos).phenotype);// agrege el primer alelo
			for (int i = 0; i < aor.size; i++) {
				if (aor.get(i).position.x < ancho / 2) {
					boolean igual = false;
					for (int j = 0; j < afen.size; j++) {
						if (afen.get(j).name
								.equals(aor.get(i).phenotype.name)) {
							igual = true;
							afen.get(j).quantity++;
						}
					}
					if (igual == false) {
						afen.add(aor.get(i).phenotype);
					}
				}
			}
			afen.sort();
		}
	}
	public void colectFenotipoD(Array aor, Array afen) {
		if (aor.size > 0) {
			int index = afen.size;
			for (int i = index - 1; i >= 0; i--) {
				afen.get(i).quantity = 1;
				afen.removeValue(afen.get(i), true);
			}
			int pos = 0;
			for (int i = 0; i < organisms.size; i++) {
				if (organisms.get(i).position.x > ancho / 2) {
					pos = i;
					i = organisms.size;
				}
			}
			aor.get(pos).phenotype.quantity = 0;
			afen.add(aor.get(pos).phenotype);// agrege el primer alelo
			for (int i = 0; i < aor.size; i++) {
				if (aor.get(i).position.x > ancho / 2) {
					boolean igual = false;
					for (int j = 0; j < afen.size; j++) {
						if (afen.get(j).name
								.equals(aor.get(i).phenotype.name)) {
							igual = true;
							afen.get(j).quantity++;
						}
					}
					if (igual == false) {
						afen.add(aor.get(i).phenotype);
					}
				}
			}
			afen.sort();
		}
	}
	public void colectarAlelos(Array aor, Array aal) {
		if (aor.size > 0) {
			int index = aal.size;
			for (int i = index - 1; i >= 0; i--) {
				aal.get(i).quantity = 1;
				aal.removeValue(aal.get(i), true);
			}
			for (int i = 0; i < aor.get(0).aAlleles.size; i = i + 2) {
				Allele al = aor.get(0).aAlleles.get(i);
				al.quantity = 0;
				aal.add(al);
			} // se agregan los alelos delprimer organismo
			for (int i = 0; i < aor.size; i++) {
				Organism or = aor.get(i);
				for (int a = 0; a < or.aAlleles.size; a++) {
					Allele al = or.aAlleles.get(a);
					boolean igual = false;
					for (int j = 0; j < aal.size; j++) {
						if (aal.get(j).name.equals(al.name)
								&& aal.get(j).identifier == al.identifier) {
							igual = true;
							aal.get(j).quantity++;
						}
					}
					if (igual == false) {
						aal.add(al);
					}
				}
			}
			aal.sort();
		}
	}
	public void colectarAlelosI(Array aor, Array aal) {
		if (aor.size > 0) {
			int index = aal.size;
			for (int i = index - 1; i >= 0; i--) {
				aal.get(i).quantity = 1;
				aal.removeValue(aal.get(i), true);
			}// limpia la lista
			int pos = 0;
			for (int i = 0; i < organisms.size; i++) {
				if (organisms.get(i).position.x < ancho / 2) {
					pos = i;
					i = organisms.size;
				}
			}
			for (int i = 0; i < aor.get(pos).aAlleles.size; i = i + 2) {
				Allele al = aor.get(pos).aAlleles.get(i);
				al.quantity = 0;
				aal.add(al);
			} // se agregan los alelos delprimer organismo
			for (int i = 0; i < aor.size; i++) {
				Organism or = aor.get(i);
				if (or.position.x < ancho / 2) {
					for (int a = 0; a < or.aAlleles.size; a++) {
						Allele al = or.aAlleles.get(a);
						boolean igual = false;
						for (int j = 0; j < aal.size; j++) {
							if (aal.get(j).name.equals(al.name)
									&& aal.get(j).identifier == al.identifier) {
								igual = true;
								aal.get(j).quantity++;
							}
						}
						if (igual == false) {
							aal.add(al);
						}
					}
				}
			}
			aal.sort();
		}
	}
	public void colectarAlelosD(Array aor, Array aal) {
		if (aor.size > 0) {
			int index = aal.size;
			for (int i = index - 1; i >= 0; i--) {
				aal.get(i).quantity = 1;
				aal.removeValue(aal.get(i), true);
			}// limpia la lista
			int pos = 0;
			for (int i = 0; i < organisms.size; i++) {
				if (organisms.get(i).position.x > ancho / 2) {
					pos = i;
					i = organisms.size;
				}
			}
			for (int i = 0; i < aor.get(pos).aAlleles.size; i = i + 2) {
				Allele al = aor.get(pos).aAlleles.get(i);
				al.quantity = 0;
				aal.add(al);
			} // se agregan los alelos delprimer organismo
			for (int i = 0; i < aor.size; i++) {
				Organism or = aor.get(i);
				if (or.position.x > ancho / 2) {
					for (int a = 0; a < or.aAlleles.size; a++) {
						Allele al = or.aAlleles.get(a);
						boolean igual = false;
						for (int j = 0; j < aal.size; j++) {
							if (aal.get(j).name.equals(al.name)
									&& aal.get(j).identifier == al.identifier) {
								igual = true;
								aal.get(j).quantity++;
							}
						}
						if (igual == false) {
							aal.add(al);
						}
					}
				}
			}
			aal.sort();
		}
	}
	// colectar todas las que aparecen
	public void colectorEspesiesTotales(Array