-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfood.h
More file actions
54 lines (42 loc) · 1.23 KB
/
food.h
File metadata and controls
54 lines (42 loc) · 1.23 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
#include <iostream>
#include <math.h>
using namespace std;
class Food {
public:
// int energy;
int nutrients_left;
int min_size;
int nibble_size;
int x;
int y;
int size;
double energy_returned_percentage;
bool deleted = false;
bool is_in_range(int cx, int cy) {
int left_x = x - size;
int right_x = x + size;
int bottom_y = y - size;
int top_y = y + size;
if (cx < max(right_x, left_x) && cx > min(right_x, left_x) && cy < max(top_y, bottom_y) && cy > min(top_y, bottom_y)) {
return true;
}
return false;
}
auto give_food(int animal_size) {
struct retGain{
int size_gain;
double energy_gain;
};
int size_gained = 0;
double energy_given = energy_returned_percentage;
// Animal can deplete this food source
if (animal_size > min_size) {
nutrients_left = 0;
return retGain{nutrients_left, energy_given};
// Animal is too small, an must nibble on this food source
} else {
nutrients_left = nutrients_left - nibble_size;
return retGain{nibble_size, energy_given};
}
}
};