1 /**
2 *   Copyright: © 2012-2014 Anton Gushcha
3 *   License: Subject to the terms of the MIT license, as written in the included LICENSE file.
4 *   Authors:  NCrashed <ncrashed@gmail.com>,
5 *             LeMarwin <lemarwin42@gmail.com>,
6 *             Nazgull09 <nazgull90@gmail.com>
7 */
8 module main;
9 
10 import std.stdio;
11 import std.process;
12 import std.conv;
13 import core.time, core.thread;
14 
15 import devol.compiler;
16 
17 import ant.progtype;
18 import ant.world;
19 import ant.app;
20 
21 import derelict.sdl2.sdl;
22 
23 alias Population!( getDefChars, Ant ) AntPopulation;
24 
25 alias 	GameCompilation!(
26     
27 	function bool(ref int x, ind, world) // stopCond
28 	{
29 		auto ai = cast(Ant)(ind);
30 		auto aw = cast(AntWorld)(world);
31 		
32 		if (ai.prevFoodCount < ai.FoodCount)
33 			x = 0;
34 		ai.prevFoodCount = ai.FoodCount;
35 		return x > 5 || aw.Food <= ai.FoodCount;
36 	},
37 	
38 	function void(ind, world) // draw step
39 	{
40 		auto ai = cast(Ant)(ind);
41 		auto aw = cast(AntWorld)(world);
42 		auto app = App.getSingleton();
43 		
44 		version(linux)
45 			system("clear");
46 		version(Windows)
47 			system("cls");
48 		
49 		app.clear();	
50 			
51 		foreach(uint j,ref l; aw.getMap() )
52 		{
53 			foreach(uint i,ref c; l)
54 			{
55 				if ( j == ai.x && i == ai.y )
56 				{
57 				    app.draw(app.ants[ai.Direction], (j+1)*32u, (i+1)*32u, 32u, 32u);
58 				}
59 				else if (c)
60 					app.draw(app.food, (j+1)*32u , (i+1)*32u, 32u, 32u);
61 				else
62 					app.draw(app.empty, (j+1)*32u , (i+1)*32u, 32u, 32u);
63 			}
64 		}
65 		
66 		foreach( i; 0..aw.size+2)
67 			app.draw(app.wall, i*32u, 0, 32u, 32u);
68 		foreach( i; 0..aw.size+2)
69 			app.draw(app.wall, i*32u, (aw.size+1)*32u, 32u, 32u);
70 		foreach( i; 0..aw.size+2)
71 			app.draw(app.wall, 0, i*32u, 32u, 32u);				
72 		foreach( i; 0..aw.size+2)
73 			app.draw(app.wall, (aw.size+1)*32u, i*32u, 32u, 32u);	
74 		
75 		app.present();									
76 	},
77 	function void(pop, world) // draw final
78 	{
79 		auto ap = cast(AntPopulation)(pop);
80 		auto aw = cast(AntWorld)(world);			
81 	},
82 	1
83 )MyCompilaton;
84 
85 alias Compiler!(
86 	MyCompilaton,
87 	Evolutor, 
88 	AntProgType, 
89 	AntPopulation, 
90 	AntWorld) 
91 AntCompiler;
92 
93 void main(char[][] args)
94 {
95 	auto app = new App;
96 	scope(exit) destroy(app);
97 	
98     auto comp = new AntCompiler;
99     auto tmng = TypeMng.getSingleton();
100     auto opmng = OperatorMng.getSingleton();
101     
102     writeln("testing population");
103     auto pop = comp.addPop(30);
104     
105     while(!app.shouldExit) {comp.envolveGeneration(() => app.shouldExit);}
106 }