
public class MyEcosystem_predprey extends CAtoolbox {

	public static void main(String[] args) {

		// initialisation generale
	    
		int dx = 20;
		int dy = 20;
		
		int displayWidth = dx;  // 200
		int displayHeight = dy; // 200

		// pick dimension for display
		if ( displayWidth < 200 )
			displayWidth = 200;
		else
			if ( displayWidth > 600 )
				displayWidth = 600;
			else
				if ( displayWidth < 300 )
					displayWidth = displayWidth * 2; 
		if ( displayHeight < 200 )
			displayHeight = 200;
		else
			if ( displayHeight > 600 )
				displayHeight = 600;
			else
				if ( displayHeight < 300 )
					displayHeight = displayHeight * 2; 
		
		
		int delai = 0;//100; // -- delay before refreshing display -- program is hold during delay, even if no screen update was requested. USE WITH CARE.
		int nombreDePasMaximum = Integer.MAX_VALUE;
		int it = 0;
		int displaySpeed = 1;//50; // from 1 to ...
		
		CAImageBuffer image = new CAImageBuffer(dx,dy);
	    ImageFrame imageFrame =	ImageFrame.makeFrame( "My Ecosystem", image, delai, displayWidth, displayHeight );

	    // initialise l'ecosysteme
	    
		World world = new World(dx,dy,true,true);

		int max_prey = 20;
		int max_predators = 15;
		
		for ( int i = 0 ; i != max_prey ; i++ )
			world.add(new PreyAgent((int) (Math.random() * dx), (int) (Math.random() * dy), world));
		for ( int i = 0 ; i != max_predators ; i++ )
			world.add(new PredatorAgent((int)(Math.random()*dx),(int)(Math.random()*dy),world));

		WorldLogger wl = new WorldLogger("stats/out_" + max_prey + "_" + max_predators + ".csv");

	    // mise a jour de l'�tat du monde
		
		while ( it != nombreDePasMaximum )
		{
			int cpt = world.cpt_proies(0);
			wl.log(it + "," + cpt);
			if (cpt == 0) {
				break;
			}

			if (it % 1000 == 0)
				world.display(image);
			// 1 - display
			
			//if ( it % displaySpeed == 0 )
			//	world.display(image);

			// 2 - update

			world.step();
						
			// 3 - iterate
			
			it++;
			
			try {
				Thread.sleep(delai);
			} catch (InterruptedException e) 
			{
			}
		}

		wl.close();
		System.exit(0);
	}

}
