-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsheep.cpp
45 lines (34 loc) · 1.28 KB
/
sheep.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
#include "sheep.h"
#include "patch.h"
#include "declare_env.h"
#include "animal.h"
#include <cstdlib>
#include <vector>
#include <iostream>
#include <cstdlib>
#include "util.h"
std::vector<Sheep> Sheep::sheepFlock;
Sheep::Sheep() : Animal() {}
Sheep::Sheep(int energy, int rows) : Animal(energy, rows) {}
Sheep::Sheep(int energy, int x, int y) : Animal(energy, x, y) {}
void Sheep::eatGrass(Patch &patch) {
// if (&patch == nullptr) {
// std::cerr << "Error: Patch reference is null." << std::endl;
// return;
// }
// std::cout << "Sheep at (" << this->x << ", " << this->y << ") attempting to eat grass." << std::endl;
// std::cout << "Patch color: " << (patch.pcolor == Patch::Color::Green ? "Green" : "Brown") << std::endl;
if (patch.pcolor == Patch::Color::Green) {
patch.setColor(Patch::Color::Brown);
this->energy += sheepGainFromFood;
}
}
Sheep Sheep::reproduceSheep(int my_rank, int world_size, int rows_per_rank) {
int offspringEnergy = this->energy / 2;
int offspringX = this->x;
int offspringY = this->y;
this->energy /= 2;
Sheep offspring(offspringEnergy, offspringX, offspringY);
offspring.move(my_rank, world_size, rows_per_rank);
return offspring;
}