-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWorldCreator.cpp
More file actions
110 lines (99 loc) · 3.45 KB
/
WorldCreator.cpp
File metadata and controls
110 lines (99 loc) · 3.45 KB
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
#include <QFileDialog>
#include <QFile>
#include <memory>
#include "WorldCreator.h"
#include "ui_WorldCreator.h"
#include "SaveManager.h"
#include "config/config.h"
#include "Herbivore.h"
#include "Carnivore.h"
WorldCreator::WorldCreator(/*World *worldToChange,*/ QWidget *parent) :
QMainWindow(parent),
ui(new Ui::WorldCreator)/*,
world(worldToChange)*/
{
ui->setupUi(this);
QLayout *animalsLayout = new QGridLayout();
QLayout *resourcesLayout = new QGridLayout();
ui->tabResources->setLayout(resourcesLayout);
ui->tabAnimaux->setLayout(animalsLayout);
resourcesLayout->addWidget(&resourceWidget);
animalsLayout->addWidget(&animalWidget);
/*setCentralWidget(&tabWidget); //replace with a clean one
tabWidget.addTab(&resourceWidget,tr("Resources"));
tabWidget.addTab(&animalWidget,tr("Animaux"));*/
QObject::connect(ui->bt_ok,SIGNAL(clicked(bool)),this,SLOT(finish()));
QObject::connect(ui->bt_cancel,SIGNAL(clicked(bool)),this,SLOT(close()));
}
WorldCreator::~WorldCreator()
{
delete ui;
}
void WorldCreator::finish()
{
SaveManager saveManager;
World world;
//TODO add code for ressources generation here
std::list<std::shared_ptr<Resource>> resources = resourceWidget.getResources();
for(std::list<std::shared_ptr<Resource>>::iterator iteResources = resources.begin(); iteResources!=resources.end(); ++iteResources)
{
world.addEntity(*iteResources);
}
//set neuralnets to entities & create entities
unsigned numH(animalWidget.getNumberOfHerbivore()), numC(animalWidget.getNumberOfCarnivore());
world.feedWithRandomHerbivore(numH);
std::list<std::shared_ptr<Entity>> entities = world.getEntities();
if(animalWidget.isHerbivoreChecked())
{
QStringList herbivores = animalWidget.getHerbivoreList();
QStringList::iterator iteReseaux = herbivores.begin();
for(std::list<std::shared_ptr<Entity>>::iterator e=entities.begin() ; e!=entities.end() ; ++e)
{
if(std::shared_ptr<Herbivore> herbivore = std::dynamic_pointer_cast<Herbivore>(*e))
{
std::cout << iteReseaux->toStdString() << std::endl;
herbivore->setBrain(saveManager.LoadNetwork(*iteReseaux));
iteReseaux++;
if (iteReseaux == herbivores.end())
{
iteReseaux = herbivores.begin();
}
}
}
}
else
{
}
numC = 0;
world.feedWithRandomCarnivore(numC);
if(animalWidget.isCarnivoreChecked())
{
QStringList carnivores = animalWidget.getCarnivoreList();
QStringList::iterator iteReseaux = carnivores.begin();
for(std::list<std::shared_ptr<Entity>>::iterator e=entities.begin() ; e!=entities.end() ; ++e)
{
if(std::shared_ptr<Carnivore> carnivore = std::dynamic_pointer_cast<Carnivore>(*e))
{
carnivore->setBrain(saveManager.LoadNetwork(*iteReseaux));
iteReseaux++;
if (iteReseaux == carnivores.end())
{
iteReseaux = carnivores.begin();
}
}
}
}
else
{
}
//put World in a predefined xmlFile
QString path(".worldCreatorGenerated.xml");
saveManager.saveWorld(world,path);
emit newWorldGenerated(path);
this->close();
}
void WorldCreator::closeEvent(QCloseEvent *e)
{
emit actionFinished();
QMainWindow::closeEvent(e);
}