-
Notifications
You must be signed in to change notification settings - Fork 1
/
h_Robot.h
executable file
·189 lines (127 loc) · 4.37 KB
/
h_Robot.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#ifndef H_ROBOT_H
#define H_ROBOT_H
#include <QVector>
#include "h_Item.h"
class NeuralNet;
class h_EatableItem;
class h_Robot : public h_Item
{
public:
h_Robot(Settings *settings, h_Simulation *aSimulation, qreal aRadius);
virtual ~h_Robot();
virtual void move();
void updateWeights(const QVector<qreal>* pGenome);
void updateWeightsFromFile(QString filename);
NeuralNet* getNeuralNet() const {return neuralNet;}
/*virtual*/ bool isRobot() const {return true;}
/*virtual*/ void reset(qreal _x, qreal _y, int _angle);
void reset();
virtual QVector<qreal> getSensors() const = 0;
virtual qreal getFitness() const = 0;
int gLSAngle1() {return lSAngle1;}
int gLSAngle2() {return lSAngle2;}
int gMSAngle1() {return mSAngle1;}
int gMSAngle2() {return mSAngle2;}
int gRSAngle1() {return rSAngle1;}
int gRSAngle2() {return rSAngle2;}
int gMaxSensorIntensity() {return maxSensorIntensity;}
protected:
void updatePosition();
void checkBorder(int mode);
protected:
qreal maxWheelSpeed;
qreal minWheelSpeed;
int maximumAngle; // Maximum angle that the robot can rotate at each iteration
NeuralNet* neuralNet;
// angles of the sensors
int lSAngle1;
int lSAngle2;
int mSAngle1;
int mSAngle2;
int rSAngle1;
int rSAngle2;
int maxSensorIntensity; // Max value returned by the captors
};
class h_Robot_1 : public h_Robot
{
public:
h_Robot_1(Settings *settings, h_Simulation *aSimulation, qreal aRadius);
/*virtual*/ void move();
/*virtual*/ QVector<qreal> getSensors() const;
/*virtual*/ qreal getFitness() const;
/*virtual*/ void reset(qreal _x, qreal _y, int _angle);
qreal getSensorScope() const {return sensorScope;}
int getFoodEaten() const {return foodEaten;}
int getPoisonEaten() const {return poisonEaten;}
protected:
virtual qreal getIntensity(int angle1, int angle2, int angleItem, qreal distanceItem) const;
virtual QVector<qreal> getSensors_1(QList<h_EatableItem*> items) const;
virtual QVector<qreal> getSensors_2(QList<h_EatableItem*> items) const;
virtual QVector<qreal> getSensors_3(QList<h_EatableItem*> items) const;
virtual QVector<qreal> getSensors_4(QList<h_EatableItem*> items) const;
void eat();
void eat(QList<h_EatableItem*> items);
void setFoodEaten(int amount) {foodEaten = amount;}
virtual void addFoodEaten(int amount) {foodEaten += amount;}
void setPoisonEaten(int amount) {poisonEaten = amount;}
virtual void addPoisonEaten(int amount) {poisonEaten += amount;}
protected:
qreal sensorScope;
int foodEaten;
int poisonEaten;
};
class h_Robot_zigzag : public h_Robot
{
public:
h_Robot_zigzag(Settings *settings, h_Simulation *aSimulation, qreal aRadius);
/*virtual*/ void move();
/*virtual*/ QVector<qreal> getSensors() const {QVector<qreal> sensorsInputs;return sensorsInputs;}
/*virtual*/ qreal getFitness() const;
/*virtual*/ void reset(qreal _x, qreal _y, int _angle);
private:
int numberRotations;
int pAngle;
int ppAngle;
QVector< int > pastRotationAngles;
QVector< int > pastAngles;
int numberIterations;
};
class h_Robot_explo : public h_Robot_1
{
public:
h_Robot_explo(Settings *settings, h_Simulation *aSimulation, qreal aRadius);
protected:
/*virtual*/ QVector<qreal> getSensors_2(QList<h_EatableItem*> items) const;
};
class h_Robot_switch : public h_Robot_1
{
public:
h_Robot_switch(Settings *settings, h_Simulation *aSimulation, qreal aRadius);
/*virtual*/ qreal getFitness() const;
/*virtual*/ void reset(qreal _x, qreal _y, int _angle);
protected:
/*virtual*/ void addFoodEaten(int amount);
/*virtual*/ void addPoisonEaten(int amount);
protected:
QList<int> eatings;
QList<int> timeEatings;
};
class h_Robot_switch_1 : public h_Robot_switch
{
public:
h_Robot_switch_1(Settings *settings, h_Simulation *aSimulation, qreal aRadius);
/*virtual*/ QVector<qreal> getSensors() const;
};
class h_Robot_switch_2 : public h_Robot_switch
{
public:
h_Robot_switch_2(Settings *settings, h_Simulation *aSimulation, qreal aRadius);
/*virtual*/ QVector<qreal> getSensors() const;
};
class h_Robot_smell : public h_Robot_1
{
public:
h_Robot_smell(Settings *settings, h_Simulation *aSimulation, qreal aRadius);
/*virtual*/ QVector<qreal> getSensors() const;
};
#endif // H_ROBOT_H