Commit 63f6cce6 authored by Anthony Noir's avatar Anthony Noir
Browse files

IT'S ALAIVE ! IT'S ALIVE !

parent dd944119
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1056</width>
<width>1068</width>
<height>771</height>
</rect>
</property>
......@@ -212,7 +212,7 @@ pattern recorded :</string>
</size>
</property>
<property name="text">
<string>50</string>
<string>10</string>
</property>
<property name="maxLength">
<number>10</number>
......@@ -605,8 +605,8 @@ pattern recorded :</string>
<rect>
<x>0</x>
<y>0</y>
<width>1056</width>
<height>25</height>
<width>1068</width>
<height>26</height>
</rect>
</property>
<widget class="QMenu" name="menuFichier">
......
......@@ -73,6 +73,12 @@ private slots:
void on_savePatternButton_clicked();
void on_nextButton_clicked();
void on_prevButton_clicked();
void on_playPauseButton_clicked();
private:
//! \brief Initialiser la liste des transitions et voisinages disponibles
void init_transition_neighborhood_list();
......@@ -114,6 +120,7 @@ private:
TransitionRule* m_transition_rule;
NeighborhoodRule* m_neighborhood_rule;
QJsonObject m_loaded_model;
QTimer* timer;
bool m_customizing;
};
#endif // MAINWINDOW_HPP
......@@ -67,6 +67,12 @@ public:
//! \brief Indique si la simulation peut tourner
//! \return vrai si la simulation peut tourner
bool runnable() {return canRun;}
//! \brief Remet la simulation dans son état de départ
void reset();
......@@ -74,7 +80,8 @@ public:
void step();
//! \brief Fais reculer la simulation d'un pas si possible
void back();
//! \return vrai si la simulation a reculé
bool back();
};
#endif // SIMULATION_HPP
......@@ -16,12 +16,14 @@
#include <QDate>
#include <QTextStream>
#include <QInputDialog>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, simulation(),
m_customizing(false)
, simulation()
, timer(new QTimer(this))
, m_customizing(false)
{
ui->setupUi(this);
......@@ -55,6 +57,12 @@ MainWindow::MainWindow(QWidget *parent)
ui->struct_library->update_cell_pixel_size(ui->grid_view->cell_screen_size());
load_model(default_model());
connect(timer, &QTimer::timeout, this, [this](){
on_nextButton_clicked();
std::cout << "a\n";
timer->start();
});
}
MainWindow::~MainWindow()
......@@ -605,3 +613,37 @@ void MainWindow::on_savePatternButton_clicked()
{
save_grid_configuration();
}
void MainWindow::on_nextButton_clicked()
{
simulation.setGrid(ui->grid_view->get_grid());
simulation.step();
ui->grid_view->copy_grid(simulation.getGrid());
}
void MainWindow::on_prevButton_clicked()
{
if(!simulation.back()) {
QMessageBox::critical(this, "Retour arrière impossible", "L'historique est vide : impossible de revenir en arrière.");
}
ui->grid_view->copy_grid(simulation.getGrid());
}
void MainWindow::on_playPauseButton_clicked()
{
if(timer->isActive()) {
//Pause
timer->stop();
} else {
//Play
int frequence = ui->simSpeedSpinbox->value();
if(frequence == 0) {
QMessageBox::critical(this, "Impossible de démarrer", "Impossible de lancer la simulation à une vitesse nulle.");
} else if(!simulation.runnable()) {
QMessageBox::critical(this, "Impossible de démarrer", "Impossible de lancer la simulation : les règles ne sont pas définies ou incompatibles.");
} else {
timer->setInterval(1000/frequence);
timer->start();
}
}
}
......@@ -15,7 +15,9 @@ mooreNeighborhoodRule::mooreNeighborhoodRule(int _radius)
for(int j = -_radius; j <= _radius; j++){
newCord.x = i;
newCord.y = j;
format.positions.push_back(newCord);
if(!(newCord.x == 0 && newCord.y == 0)) {
format.positions.push_back(newCord);
}
}
}
}
......
......@@ -5,13 +5,13 @@ Simulation::Simulation() : canRun(false), time(0), automaton(), startGrid(0,0),
Simulation::~Simulation() {}
void Simulation::setNeighborhoodRule(NeighborhoodRule* NR) {
canRun = false;
automaton.setNeighborhoodRule(NR);
canRun = automaton.getNeighborhoodRule()&&automaton.getTransitionRule()&&automaton.getTransitionRule()->acceptFormat(automaton.getNeighborhoodRule()->getFormats());
}
void Simulation::setTransitionRule(TransitionRule* TR) {
canRun = false;
automaton.setTransitionRule(TR);
canRun = automaton.getNeighborhoodRule()&&automaton.getTransitionRule()&&automaton.getTransitionRule()->acceptFormat(automaton.getNeighborhoodRule()->getFormats());
}
void Simulation::setAlphabet(const Alphabet& A) {
......@@ -71,11 +71,14 @@ void Simulation::step() {
++time;
}
void Simulation::back() {
bool Simulation::back() {
bool r=false;
if(!hist.isEmpty()) {
automaton.setGrid(hist.topGrid());
//automaton.getNeighborhoodRule()->back();
hist.popGrid();
--time;
r=true;
}
return r;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment