-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
94 lines (78 loc) · 2.96 KB
/
main.cpp
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
94
#include <iostream> // prints stuff to screen
#include <vector> // dynamic arrays that handle thier own memory cleanup
#include <cstdlib> // for rand() and srand()
#include <ctime> // for time()
#include <cassert> // for assert()
#include "gnuplot-iostream.h"
#include "food.h"
#include "blob.h"
#include "randNum.h" //random number generator
#include "map.h"
#include "simulationResults.h"
#include "graphs.h"
#include "simulation.h"
#include "animation.h"
int main()
{
srand(static_cast<unsigned int>(time(0))); // set initial seed value to system clock
rand(); // remove first value
Map map;
std::vector<Blob> blobArray;
std::vector<Food> foodArray;
simulationResults stats;
//INITIAL BLOB STATS
double nativeEnergy{ 1400.0 };
double seedSize{ 3.0 };
double seedSpeed{ 3.0 };
double seedSense{ 3.0 };
Blob seedBlob( nativeEnergy, seedSize, seedSpeed, seedSense);
//ENVIRONMENT VARIABLES
map.setMapSize( 10 ); //Integer length, in grid spaces, of one side of the square map
int seedBlobCount{ 20 }; //Starting number of Blobs
int foodCount{ 30 }; //Number of food pieces place randomly on map daily
//SIMULATION VARIABLES
g_mutationProb = 25; //Integer probability (%) of a blob stat mutating during replication
int dayCount{ 100 }; //Length of simulation in days
int simCount{ 1 }; //Number of repeat simulations run
//GRAPH VARIABLES
int firstSim{ 0 }, lastSim{ 0 }; //Range of simulation runs to create histogram gifs for
//ANIMATION VARIABLES
int yResolution{ 600 }; //Animation window resolution in pixels
int xResolution{ 850 };
Animation::ColourStat colourStat{ Animation::SPEED }; // SIZE, SPEED or SENSE
std::string vidName{ }; //Video filename, if blank default of xM_xB_xF_xD_Stat is used
for (int sim{ 0 }; sim < simCount; ++sim)
{
g_nameHolder = seedBlobCount + 1; //For specific blob naming, allows error tracking
blobArray = map.populateBlobs(seedBlob, seedBlobCount);
foodArray = map.populateFood(foodCount);
for (int day{ 0 }; day < dayCount; ++day)
{
stats.recordDay(blobArray, foodArray);
std::cout << "Run #" << sim << ", Day #" << day << "\n";
walkAndEat(blobArray, foodArray, stats);
stats.pushBlobFrames();
naturalSelection(blobArray);
//a check to end early incase of extinction
if (blobArray.size() == 0)
{
std::cout << "Extinction at end of day " << day << "\n";
break;
}
breed(blobArray);
digestAndSleep(blobArray);
foodArray = map.populateFood(foodCount);
}
stats.recordSim();
}
//GRAPHS OUTPUT
makeAvgGraphs(stats); //line graph of population and mean size, speed and sense each day
makeHistogram(stats, firstSim, lastSim); //Creates gif of daily size, speed and sense distribution
//ANIMATION
Animation blobSim(map.getMapSize(), stats, vidName, colourStat); //Creates animation object
if (blobSim.Construct(xResolution, yResolution, 1, 1)) //Runs animation
{
blobSim.Start();
}
return 0;
}