-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plankton.cpp
49 lines (42 loc) · 1.17 KB
/
Plankton.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
46
47
48
49
#include "Plankton.h"
#include <random>
Plankton::Plankton(Gene gene, Coordinates position, unsigned int id)
: Creature(LifeType::PLANKTON, gene, LifeType::PLANKTON, position, id), mt(rd())
{
that = this;
}
Plankton::~Plankton()
{
}
bool Plankton::thinkAboutIt(std::list<Creature*>& creatures, Coordinates borders)
{
/*если мы не достигли цели, то ничего не меняем
если достигли, то ставим новую цель*/
if (getPosition().getDistance(direction) < 10+gene.speed)
{
std::uniform_int_distribution<int> distx(0, borders.x);
direction.x = distx(mt);
std::uniform_int_distribution<int> disty(0, borders.y);
direction.y = disty(mt);
std::uniform_int_distribution<int> distz(0, borders.z);
direction.z = distz(mt);
return true;
}
else
{
return false;
}
}
bool Plankton::reproduce(std::list<Creature*>& creatures)
{
if (reproductionReady == gene.reproductionPeriod)
{
reproductionReady = 0;
throwEvent(position, EventType::BIRTH, this);
return true;
}
else
{
return false;
}
}