-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeathFunctionTests.cpp
More file actions
62 lines (49 loc) · 1.38 KB
/
DeathFunctionTests.cpp
File metadata and controls
62 lines (49 loc) · 1.38 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
/*
Test death function of Animats to determine if an artifical carrying capacity has been created
*/
#include <iostream>
#include <time.h>
#include <string>
#include <vector>
using namespace std;
//method declaration
int deathFunction(int); //determines number of deaths
int main()
{
//variables
srand(time(NULL)); //random number voo-doo
int population = 10; //starting population
//main testing
for (;;)
{
cout << "Starting Population: " << population << endl;
population = deathFunction(population); //run death algorithm
cout << "Death Count: " << population << endl;
population *= 2; //double population similar to reproduction
cout << "Ending Population: " << population << endl;
system("pause&cls");
}
//end program
system("pause");
return 0;
}
int deathFunction(int population) //determines number of deaths
{
//variables
int rNum, dead = 0;
vector <bool> animats(population); //create population of animats with the passed size
//run death algorithm
for (int a = 0; a < population; a++) //go through current generation...
{
rNum = rand() % population;
for (int b = 0; b < a; b++) //check every number from 0 to their rank to see if they died
{
if (rNum == b) //if the range includes the animat's number, it dies off
{
animats[a] = 0; //kill animat
dead++;
}
}
}
return dead;
}