-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrey.h
64 lines (47 loc) · 1.55 KB
/
Prey.h
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
#ifndef PREY_H
#define PREY_H
#include "Animal.h"
#include "Food.h"
#include "ReactionDiffusion.h"
class Predator;
class Prey : public Animal {
// Source for basic boid rules: http://www.kfish.org/boids/pseudocode.html
protected:
int vision_int;
Food* food;
public:
Food* getFood() {
return food;
}
Prey(Food* f, const Animal &an)
: Animal(an), vision_int(vision * 50), food(f) {
react = ReactionDiffusion(0.0545, 0.062);
react.initReact(skin_xinit, skin_yinit, skin_radius);
genTexture();
}
static Prey* individual(Food* f, const std::vector<Point> *shape) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis_vision_c(.1, .25);
Animal an = Animal::individual(shape);
an.setVision(dis_vision_c(gen));
return new Prey(f, an);
}
void update(const std::vector<Prey*> &preys,
const std::vector<Predator*> &predators);
unsigned int getFoodStock() {
return foodStock;
}
Prey* crossoverMutation(const Prey &o) const {
Animal a = Animal::crossoverMutation(o);
return new Prey(food, a);
}
private:
bool escapePredator(const std::vector<Predator*> &predators,
std::pair<double, double> &newDirection) const;
void eatFood();
std::pair<double, double> cohesion(const std::vector<Prey*> &preys) const;
std::pair<double, double> alignment(const std::vector<Prey*> &preys) const;
std::pair<double, double> foodMove() const;
};
#endif /* PREY_H */