Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LO21_Pin_Noir_Boucher_Bouri_Detree
CellulutLO21
Commits
63f6cce6
Commit
63f6cce6
authored
Jun 05, 2021
by
Anthony Noir
Browse files
IT'S ALAIVE ! IT'S ALIVE !
parent
dd944119
Changes
6
Show whitespace changes
Inline
Side-by-side
forms/interface.ui
View file @
63f6cce6
...
...
@@ -6,7 +6,7 @@
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
10
5
6
</width>
<width>
106
8
</width>
<height>
771
</height>
</rect>
</property>
...
...
@@ -212,7 +212,7 @@ pattern recorded :</string>
</size>
</property>
<property
name=
"text"
>
<string>
5
0
</string>
<string>
1
0
</string>
</property>
<property
name=
"maxLength"
>
<number>
10
</number>
...
...
@@ -605,8 +605,8 @@ pattern recorded :</string>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
10
5
6
</width>
<height>
2
5
</height>
<width>
106
8
</width>
<height>
2
6
</height>
</rect>
</property>
<widget
class=
"QMenu"
name=
"menuFichier"
>
...
...
include/interface.hpp
View file @
63f6cce6
...
...
@@ -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
include/simulation.hpp
View file @
63f6cce6
...
...
@@ -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
src/interface.cpp
View file @
63f6cce6
...
...
@@ -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
();
}
}
}
src/neighborhood_rules/mooreNeighborhoodRule.cpp
View file @
63f6cce6
...
...
@@ -15,9 +15,11 @@ mooreNeighborhoodRule::mooreNeighborhoodRule(int _radius)
for
(
int
j
=
-
_radius
;
j
<=
_radius
;
j
++
){
newCord
.
x
=
i
;
newCord
.
y
=
j
;
if
(
!
(
newCord
.
x
==
0
&&
newCord
.
y
==
0
))
{
format
.
positions
.
push_back
(
newCord
);
}
}
}
}
Neighborhood
mooreNeighborhoodRule
::
getNeighborhood
(
const
Grid
&
grid
,
Coord
pos
)
const
...
...
src/simulation.cpp
View file @
63f6cce6
...
...
@@ -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
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment