-
Notifications
You must be signed in to change notification settings - Fork 0
/
geneticworld.h
93 lines (71 loc) · 1.82 KB
/
geneticworld.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef GENETICWORLD_H
#define GENETICWORLD_H
#include <QThread>
#include <QSet>
#include <QHash>
#include <QMutex>
#include <QElapsedTimer>
#include <QPoint>
#include <cassert>
#include <cmath>
#include "botstruct.h"
#include "enums.h"
class GeneticWorld : public QThread {
Q_OBJECT
protected:
void run();
public: // == settings ==
~GeneticWorld();
Bot *newBot(QPoint xy);
void stop();
uint getPhotosynthesisEnergy(int y);
uint getMineralsCount(uint y);
float getPhotosynthesisCoefficient();
bool runFlag;
uint worldPartsCount;
uint startWorldPhotosynthesisEnergy;
uint startWorldMinerals;
uint mineralsPartSize;
float minPhotosynthesisCoefficient;
uint processDelay;
uint generationsInYear;
// bots
float botMutateChance;
uint genomeLen;
uint maxEnergy;
uint maxOld;
uint maxBotCount;
uint organicEnergy;
uint reproductionPrice;
bool organicEnabled;
int mutateGenRange;
uint mineralPrice;
// commands settings
float steal_coeff;
uint mutateAttackCount;
int maxX, maxY;
int partLength;
//statistic
uint generation = 0;
uint aliveBotsCount = 0;
uint processingTime = 0;
QHash<ulong, Bot*> bots;
//QMutex botsMutex;
private:
QSet<Bot*> killedBots;
void deadBot2Alive(Bot* bot);
bool checkSimilarity(Bot *bot1, Bot *bot2);
void translateCoords(QPoint &xy);
QPoint oppositeBot(Bot *bot);
int checkCoords(QPoint xy);
bool reproduction(Bot *bot);
void moveBot(Bot *bot, QPoint xy);
void organicStep(Bot *bot);
void botStep(Bot *bot);
void mutateBotGenome(Bot *bot);
inline uint botPart(Bot *bot);
inline void eatBot(Bot *bot, bool noOrganic=false);
inline void clearOrganic(Bot *bot);
void clearKilled();
};
#endif // GENETICWORLD_H