-
Notifications
You must be signed in to change notification settings - Fork 0
/
p3.C
executable file
·78 lines (63 loc) · 1.59 KB
/
p3.C
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cassert>
#include "world_type.h"
#include "simulation.h"
using namespace std;
int main()
{
world_t world;
string argcLine;
getline(cin, argcLine);
istringstream iStream;
iStream.str(argcLine);
string Argc[4];
int n=0;
bool ifVerbose = 0;
while (iStream>>Argc[n] && n<=4)
{
n++;
}
if (Argc[n-1]=="v" || Argc[n-1]=="verbose")
{
ifVerbose = 1;
if (n<=3)
{
cout<<"Error: Missing arguments!"<<endl
<<"Usage: ./p3 <species-summary> <world-file> <rounds> [v|verbose]"<<endl;
exit(1);
}
}
else if (n<=2)
{
cout<<"Error: Missing arguments!"<<endl
<<"Usage: ./p3 <species-summary> <world-file> <rounds> [v|verbose]"<<endl;
exit(1);
}
int rounds = atoi(Argc[2].c_str());
if (rounds < 0)
{
cout<<"Error: Number of simulation rounds is negative!"<<endl;
exit(1);
}
initWorld(world, Argc[0], Argc[1]);
cout<<"Initial state"<<endl;
printGrid(world.grid);
for (int i=1; i<=rounds; i++)
{
cout<<"Round"<<" "<<i<<endl;
for(int j=0; j<world.numCreatures; j++)
{
simulateCreature(world.creatures[j], world.grid, ifVerbose);
}
if (ifVerbose == 0)
{
printGrid(world.grid);
}
}
return 0;
}