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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
#ifndef __PARAMS_HPP__
#define __PARAMS_HPP__
#include <sstream>
#include <cmath>
#include <SFML/Graphics.hpp>
#include <Box2D.h>
#include <NeuralNetworks.hpp>
enum SimStyle
{
SELECTION_BY_FITNESS
};
struct Params
{
// Variable parameters must be defined before simulation starts
// Simulation params
SimStyle simStyle = SELECTION_BY_FITNESS;
// If selection by fitness
NeuralNetClass netClass = SIMPLE_RN;
NodeClass nodeClass = MEMORY_CELL;
unsigned npHiddenLayer = 80;
unsigned popSize = 30;
unsigned popQtty = 10;
unsigned elites = 30;
// World params
float worldRad = 40.f;
// Entity params
float zapperForce = 50.f;//100
float zapperTorque = 150.f;//300
unsigned zapperQtty = 20;
unsigned pelletQtty = 400;
unsigned pelletCreationDelay = 150;
bool startScarce = false;
bool corpseDecay = true;
float corpseDecayTime = 3600.f;
// Goopy params
unsigned activationDelay = 120;
unsigned contactSteps = 15;
float thrustForce = 5.f;
float thrustRadius = 0.05f;
float initEnergy = 60.f;
float maxEnergy = 180.f;
float agingRate = 600.f;
bool leaveCorpse = true;
// Energy transfers
float etFromZapper = -20.f;
float etFromPellet = 15.f;
float etFromGuppie = 60.f;
float etFromCorpse = 60.f;
// Fitness bonus
float forPellet = 9000.f;
float forGuppie = 36000.f;
float forCorpse = 36000.f;
float forGoingStraight = 12.f;
// Colors
sf::Color clearColor = { 0, 0, 10 };
sf::Color worldColor = { 0, 0, 0 };
sf::Color textColor = { 191, 191, 191 };
sf::Color zapperColor = { 0, 0, 255 };
sf::Color pelletColor = { 0, 255, 0 };
sf::Color corpseColor = { 0, 255, 0 };
sf::Color guppieColorI = { 255, 0, 0 };
sf::Color glandColor1 = { 255, 127, 0 };
sf::Color glandColor2 = { 0, 255, 127 };
sf::Color glandColor3 = { 127, 0, 255 };
// Constant values cant be changed
constexpr static unsigned WIN_WIDTH = 800;
constexpr static unsigned WIN_HEIGHT = 600;
constexpr static unsigned ANTIALIAS = 8;
constexpr static unsigned CAM_STEPS = 8;
constexpr static float ZAPPER_RAD = 5.f;
constexpr static float GUPPIE_RAD = 0.5f;
constexpr static float EGG_RAD = 1.5f;
constexpr static float CORPSE_RAD = 0.25f;
constexpr static float PELLET_RAD = 0.1f;
constexpr static float TXT_SIZE = 12.f;
constexpr static float MAX_ZOOM = 0.002f;
constexpr static float RAD_DGRS = 57.2957795f;
};
// Utility functions
template <class T>
inline std::string nts(T num)
{
std::ostringstream ss;
ss << num;
return ss.str();
}
inline sf::Vector2f vecMult(const sf::Vector2f &v1, const sf::Vector2f &v2)
{
return sf::Vector2f(v1.x * v2.x, v1.y * v2.y);
}
inline void setCenterRad(sf::CircleShape &circle, float radius)
{
circle.setRadius(radius);
circle.setOrigin(radius, radius);
}
inline sf::Color mix(const sf::Color &clr1, const sf::Color &clr2, float f1 = 0.2f)
{
sf::Color result;
float f2 = 1.f - f1;
result.r = clr1.r * f1 + clr2.r * f2;
result.g = clr1.g * f1 + clr2.g * f2;
result.b = clr1.b * f1 + clr2.b * f2;
return result;
}
// Utility classes
class QueryCallback : public b2QueryCallback
{
public:
bool ReportFixture(b2Fixture* fixture)
{
b2Body* body = fixture->GetBody();
if (body->GetType() != b2_staticBody)
{
bool inside = fixture->TestPoint(m_point);
if (inside)
{
m_fixture = fixture;
return false;
}
}
return true;
}
b2Vec2 m_point;
b2Fixture *m_fixture = nullptr;
};
class RayCastCallback : public b2RayCastCallback
{
public:
float32 ReportFixture(b2Fixture *fixture, const b2Vec2 &point, const b2Vec2 &normal, float32 fraction)
{
m_fixture = fixture;
m_fraction = fraction;
return fraction;
}
float m_fraction = 0.f;
b2Fixture *m_fixture = nullptr;
};
#endif // __PARAMS_HPP__
|