-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
93 lines (77 loc) · 2.24 KB
/
main.cpp
File metadata and controls
93 lines (77 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/** Author Stephane LE BOEUF : stephane.leboeuf@digital-lab.fr **/
#include "Ant.hpp"
#include <unistd.h>
#include <iostream>
int main(int argc, char** argv)
{
int c;
const char * config = NULL;
const char * output = NULL;
bool display = true;
int iter = 0;
while ((c = getopt (argc, argv, "i:o:dhn:")) != -1)
{
switch (c)
{
case 'i':
{
config = optarg;
break;
}
case 'o':
{
output = optarg;
break;
}
case 'd':
{
display = false;
break;
}
case 'n':
{
iter = atoi(optarg);
break;
}
case 'h':
default:
{
std::cout << "-[ HELP ]-"<< std::endl;
std::cout << " -d interactive display off" << std::endl;
std::cout << " -h this help" << std::endl;
std::cout << " -i <string> use a config file ( cf gold.mpc )" << std::endl;
std::cout << " -o <string> output filename (PNG, JPEG ...)" << std::endl;
std::cout << " -n <int> number of iteration ( 0 = infinity )" << std::endl;
return 0;
}
}
}
Game * myGame;
if(config)
myGame = new Game(config);
else
myGame = new Game();
Ant myAnt(myGame->getSize());
CImgDisplay main_disp;
if(display)
main_disp.assign(myGame->map,"Ant");
if( iter==0 && !display )
{
std::cout << "You do not display the result and you ask for an infinity simulation : somethng wrong" <<std::endl;
return 0;
}
for(int i = 0; ( iter==0 || i < iter ) && (!display
|| !main_disp.is_closed()); ++i)
{
myAnt.visit(myGame);
if(display)
main_disp.display(myGame->map);
myAnt.updatePosition();
usleep(1000);
}
if(output)
myGame->map.save(output);
delete myGame;
return 0;
}
/** Author Stephane LE BOEUF : stephane.leboeuf@digital-lab.fr **/