-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAnimal.cpp
More file actions
87 lines (77 loc) · 2.3 KB
/
Animal.cpp
File metadata and controls
87 lines (77 loc) · 2.3 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
/*
Authors: Andrew Yoder, Thomas Stryjski, Zachary O'Brien
Email: aby7159@rit.edu, tgs9181@rit.edu, zjo5244@rit.edu
Date: 12/5/18
Class: EEEE-346-01
Assignment: Project 3
Purpose: Executes functions declared in Animal.h
*/
#include "Animal.h"
#include "Miscellaneous.h"
//constructors
Animal::Animal(double x, double y) {
consumption_amount = 1;
consumption_time = 5;
reproduction_amount = 2;
reproduction_time = 3;
reproduction_counter = reproduction_time;
consumption_food_counter = consumption_amount;
consumption_time_counter = consumption_time;
age = 0;
movement = 3;
spawn_distance = 4;
visibility = 2;
//temp setter
o2 = 5;
co2 = 5;
fertility = 1;
setLocation(x, y);
}
//getters
double Animal::get_co2() {
return co2;
}
double Animal::get_fertility() {
return fertility;
}
//setters
void Animal::set_o2(double x) {
o2 = x;
}
void Animal::set_co2(double x){
co2 = x;
}
void Animal::set_fertility() {
//after having tried upside-down parabolas to unsucessfully model organisms having optimal fertility, we discovered the amazing gaussian curve!
//format , in this case: e^(-1/a * (x-d)^(2)), where a is the horizontal strech factor of the curve and d is the desired/optimal value where the function = 1
double temper = exp((-1 / 200) * pow((temperature - 50), 2));
double oxygen = exp((-1 / 10000) * pow((o2 - 300), 2));
if (o2 <= 0) {
fertility = 0;
}
else {
fertility = 1 + temper + oxygen;
}
}
//other
void Animal::reproduce(Animal *A, double x_max, double y_max) {
double theta, x, y;
do {
theta = fRand(0, 2 * 3.14159265);
x = round((l.getX() + spawn_distance * cos(theta))*10000)/10000;
y = round((l.getY() + spawn_distance * sin(theta))*10000)/10000;
} while ((x > x_max) || (x < -(x_max)) || (y > y_max) || (y < -(y_max)));
A->setLocation(x, y);
}
void Animal::aged() {
age++;
movement = movement - (age / 20); //decereases movement the older the cell is, although this is scaled by the constant 10. Accumulates
spawn_distance = 4 - (age / 100);//decreases spawn distance as the cell gets older, scaled by the constant 100. Acculmulates
}
Animal Animal::operator+(Plant *p) {
Point newLocation = p->getLocation();
this->setLocation(newLocation);
dec_con_food_counter();
// delete p;
return *this;
}