Newer
Older
#include "actionGoTo.h"
Etape::Etape(){}
Etape::Etape(int numero)
{
this->position = Position();
this->type = POINT_PASSAGE;
this->state = -1;
this->numero = numero;
this->nombreEtapesLieesParFinirEtape = 0;
postInit();
}
Etape::Etape(int numero, MediumLevelAction* action)
{
this->position = Position();
this->type = POINT_PASSAGE;
this->state = -1;
this->numero = numero;
this->nombreEtapesLieesParFinirEtape = 0;
postInit();
setAction(action);
}
Etape::Etape(int numero, Position position, EtapeType type, int state, int nombreEtapesLieesParFinirEtape)
{
this->position = position;
this->type = type;
this->state = state;
this->numero = numero;
this->nombreEtapesLieesParFinirEtape = nombreEtapesLieesParFinirEtape;
this->numeroEtapeFinAction = numero;//Par défaut, on fini à l'endroit de l'étape
//Initialisation du tableau de voisins à vide
/*for(int i = 0 ; i < nbChildren ; i++)
}*/
postInit();
Etape::Etape(Position position, int numero, Etape** tableaudebug, EtapeType type, int state, int nombreEtapesLieesParFinirEtape)
{
this->position = position;
this->type = type;
this->state = state;
this->numero = numero;
this->nombreEtapesLieesParFinirEtape = nombreEtapesLieesParFinirEtape;
postInit();
}
void Etape::postInit()
{
this->action = 0;
this->nbChildren = 0;
this->distance = -1;
this->score = 0;
this->numeroEtapeFinAction = numero;//Par défaut, on fini à l'endroit de l'étape
this->actionGoTo = new ActionGoTo(getPosition());
}
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
Etape* Etape::getChild(int nb){
return this->children[nb];
}
Etape** Etape::getChildren(){
return this->children;
}
Etape* Etape::getParent(){
return this->parent;
}
Position Etape::getPosition()
{
return this->position;
}
int Etape::getState(){
return this->state;
}
void Etape::setState(int state){
this->state = state;
}
int Etape::getDistance(){
return this->distance;
}
void Etape::setDistance(int distance){
this->distance = distance;
}
void Etape::setParent(Etape* parent){
this->parent = parent;
}
int Etape::getNbChildren(){
return this->nbChildren;
}
void Etape::setChildren(Etape** children)
{
this->children = children;
}
Etape::EtapeType Etape::getEtapeType()
{
return this->type;
}
void Etape::setEtapeType(Etape::EtapeType type)
{
this->type = type;
}
void Etape::robotVu()
{
Cecile Bouette
committed
this->type = (EtapeType)(this->type + ROBOT_VU_ICI);
}
int Etape::getNumero()
{
return this->numero;
}
Cecile Bouette
committed
if(((int) this->getEtapeType()) > ROBOT_VU_ICI-1)
{
return true;
}
else
{
return false;
}
}
void Etape::oublieRobotVu()
{
if(this->aEviter())
{
//On oublie qu'on a vu un robot
Cecile Bouette
committed
this->setEtapeType((EtapeType) ((int)this->getEtapeType() - ROBOT_VU_ICI));
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
}
}
int* Etape::getDistances()
{
return this->distances;
}
void Etape::setDistances(int* distances)
{
this->distances = distances;
}
void Etape::computeChildDistances(){
this->distances = new int[this->nbChildren];
for(int i=0; i<this->nbChildren; i++)
{
this->distances[i] = Dijkstra::calculDistanceDirect(this->children[i], this);
}
}
int* Etape::getEtapesLieesParFinirEtape()
{
return this->numerosEtapesLieesParFinirEtape;
}
void Etape::setEtapesLieesParFinirEtape(int* numerosEtapesLieesParFinirEtape)
{
this->numerosEtapesLieesParFinirEtape = numerosEtapesLieesParFinirEtape;
}
int Etape::getNombreEtapesLieesParFinirEtape()
{
return this->nombreEtapesLieesParFinirEtape;
}
void Etape::finir(void)
{
{
this->type = POINT_PASSAGE;
}
}
void Etape::setScore(int score)
{
this->score = score;
}
int Etape::getScore()
{
return this->score;
}
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
void Etape::setAction(MediumLevelAction *action)
{
this->action = action;
if (this->position == Position())
{
this->position = action->getGoalPosition();
this->type = action->getType();
if (this->actionGoTo != 0)
delete this->actionGoTo;
this->actionGoTo = new ActionGoTo(getPosition());
}
}
MediumLevelAction* Etape::getAction()
{
return this->action;
}
ActionGoTo* Etape::getActionGoTo()
{
return this->actionGoTo;
}
void Etape::addVoisin(Etape* newVoisin, bool autreSens)
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
{
if(this->nbChildren==0)
{
this->children = new Etape*[1];
this->children[0] = newVoisin;
this->nbChildren++;
}
else
{
Etape** temp = new Etape*[nbChildren];
for(int i=0; i<nbChildren; i++)
{
temp[i] = this->children[i];
}
this->children = new Etape*[nbChildren+1];
for(int i=0; i<nbChildren; i++)
{
this->children[i] = temp[i];
}
delete[] temp;
this->children[nbChildren] = newVoisin;
this->nbChildren++;
}
/*int i = 0;
//On cherche le premier voisin non-initialisé
while(this->children[i]!=0 && i < this->nbChildren)
{
i++;
}
//Erreur, il y a trop de voisins !
if (i == nbChildren)
{
#ifndef ROBOTHW
qDebug() << "ERREUR, TROP DE VOISINS !!!";
#endif
}
this->children[i] = newVoisin;
*/
if (autreSens)
{
newVoisin->addVoisin(this, false);
}
}
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
void Etape::reset()
{
if (this->action != 0)
this->action->reset();
if (this->actionGoTo != 0)
this->actionGoTo->reset();
}
void Etape::setGoBack(bool val)
{
if (this->action != 0)
this->action->setGoBack(val);
if (this->actionGoTo != 0)
this->actionGoTo->setGoBack(val);
}
void Etape::addVoisin(int newVoisinIndex, bool autreSens)
{
this->addVoisin(get(newVoisinIndex), autreSens);
}
void Etape::addVoisins(int newVoisinIndex)
{
this->addVoisin(newVoisinIndex);
}
void Etape::addVoisins(int newVoisinIndex1, int newVoisinIndex2)
{
this->addVoisin(newVoisinIndex1);
this->addVoisin(newVoisinIndex2);
}
void Etape::addVoisins(int newVoisinIndex1, int newVoisinIndex2, int newVoisinIndex3)
{
this->addVoisin(newVoisinIndex1);
this->addVoisin(newVoisinIndex2);
this->addVoisin(newVoisinIndex3);
}
void Etape::addVoisins(int newVoisinIndex1, int newVoisinIndex2, int newVoisinIndex3, int newVoisinIndex4)
{
this->addVoisin(newVoisinIndex1);
this->addVoisin(newVoisinIndex2);
this->addVoisin(newVoisinIndex3);
this->addVoisin(newVoisinIndex4);
}
void Etape::addVoisins(int newVoisinIndex1, int newVoisinIndex2, int newVoisinIndex3, int newVoisinIndex4, int newVoisinIndex5)
{
this->addVoisin(newVoisinIndex1);
this->addVoisin(newVoisinIndex2);
this->addVoisin(newVoisinIndex3);
this->addVoisin(newVoisinIndex4);
this->addVoisin(newVoisinIndex5);
}
void Etape::setNumeroEtapeFinAction(int newNumeroEtapeFinAction)
{
this->numeroEtapeFinAction = newNumeroEtapeFinAction;
}
int Etape::getNumeroEtapeFinAction()
{
return this->numeroEtapeFinAction;
}
Etape** Etape::initTableauEtapeTotal(int number)
{
for(int i(0); i<number; ++i)
tableaudebug[i] = 0;
return tableaudebug;
}
Etape* Etape::get(int index)
{
new Etape(index);
}
{
}
#ifndef ROBOTHW
QString Etape::getNameType(EtapeType type)
{
switch(type)
{
Guillaume Buret
committed
case CABINE:
return "Cabine";
case POINT_PASSAGE:
return "Passage";
case DEPART:
return "Départ";
case CLAP:
return "Clap";
case GOBELET:
return "Gobelet";
case RAMASSER_PIED:
return "Pied";
case AMPOULE:
return "Ampoule";
case TAPIS:
return "Tapis";
Cecile Bouette
committed
case DEPOSER_GOBELET:
return "Déposer Gobelet";
default:
return QString::number(type);
}
}
QString Etape::getShortNameType(EtapeType type)
{
switch(type)
{
Guillaume Buret
committed
case CABINE:
return "Cabine";
case POINT_PASSAGE:
return "";
case DEPART:
return "Start";
case CLAP:
return "Clap";
case GOBELET:
return "Gob";
case RAMASSER_PIED:
return "Pied";
case AMPOULE:
return "Amp";
case TAPIS:
return "Tapis";
Cecile Bouette
committed
case DEPOSER_GOBELET:
return "D.G";
default:
return "";
}
}
#endif