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
404c2d5b
Commit
404c2d5b
authored
Jun 11, 2021
by
Yann Boucher
Browse files
Ajout de Margolus
parent
fd479439
Pipeline
#79630
passed with stages
in 17 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
include/neighborhood_rules/margolusNeighborhoodRule.hpp
0 → 100644
View file @
404c2d5b
/**
\file vonNeumannNeighborhoodRule.hpp
\date 13/05/2021
\author Eugene Pin
\version 1
\brief vonNeumannNeighborhoodRule
Contient la classe de la règle de Von Neumann.
**/
#ifndef MARGOLUSNEIGHBORHOODRULE_HPP
#define MARGOLUSNEIGHBORHOODRULE_HPP
#include "neighborhoodrule.hpp"
#include "neighborhood.hpp"
//! \brief Voisinage de Margolus.
class
MargolusNeighborhoodRule
:
public
NeighborhoodRule
{
public:
MargolusNeighborhoodRule
();
//! \brief Retourne l'ensemble des voisins d'une cellule de position 'pos' sur la grille 'grid' sous la forme d'une structure 'Neighborhood'
//! \return L'ensemble des voisins de la cellule à 'pos'
Neighborhood
getNeighborhood
(
const
Grid
&
grid
,
Coord
pos
)
const
;
//! \brief Retourne 'format' de VonNeumann dans un vecteur (méthode dérivée)
//! \return Retourne les formats de voisinage possible dans un std::vector.
std
::
vector
<
NeighborhoodFormat
>
getFormats
()
const
;
virtual
void
update_generation
(
unsigned
gen
)
{
parity
=
gen
%
2
;
}
private:
std
::
vector
<
NeighborhoodFormat
>
formats
;
unsigned
parity
;
};
#endif // MARGOLUSNEIGHBORHOODRULE_HPP
src/neighborhood_rules/margolusNeighborhoodRule.cpp
0 → 100644
View file @
404c2d5b
#include "margolusNeighborhoodRule.hpp"
REGISTER_FACTORY_ENTRY
(
NeighborhoodRule
,
MargolusNeighborhoodRule
,
"Margolus"
);
MargolusNeighborhoodRule
::
MargolusNeighborhoodRule
()
:
parity
(
0
)
{
formats
.
resize
(
2
);
formats
[
0
].
positions
.
push_back
({
-
1
,
-
1
});
formats
[
0
].
positions
.
push_back
({
-
1
,
0
});
formats
[
0
].
positions
.
push_back
({
0
,
-
1
});
NeighborhoodFormat
format_2
;
formats
[
1
].
positions
.
push_back
({
+
1
,
+
1
});
formats
[
1
].
positions
.
push_back
({
+
1
,
0
});
formats
[
1
].
positions
.
push_back
({
0
,
+
1
});
}
Neighborhood
MargolusNeighborhoodRule
::
getNeighborhood
(
const
Grid
&
grid
,
Coord
pos
)
const
{
Neighborhood
newNeighborhood
;
// Coordonnées des voisins dans la grille
Coord
gridCoord
;
const
NeighborhoodFormat
&
format
=
formats
[
parity
];
std
::
vector
<
Coord
>::
const_iterator
it
=
format
.
positions
.
begin
();
for
(
it
=
format
.
positions
.
begin
()
;
it
!=
format
.
positions
.
end
();
++
it
)
{
// Calcul des coordonnées du voisin sur la grille
gridCoord
.
x
=
pos
.
x
+
it
->
x
;
gridCoord
.
y
=
pos
.
y
+
it
->
y
;
// Ajout du nouveau voisin <Coordonnée_relative, état>
newNeighborhood
.
addNeighbor
(
*
it
,
grid
.
get_state
(
gridCoord
));
}
return
newNeighborhood
;
}
std
::
vector
<
NeighborhoodFormat
>
MargolusNeighborhoodRule
::
getFormats
()
const
{
return
formats
;
}
src/src.pro
View file @
404c2d5b
...
@@ -25,6 +25,7 @@ SOURCES += \
...
@@ -25,6 +25,7 @@ SOURCES += \
alphabet
.
cpp
\
alphabet
.
cpp
\
mathexpr
.
cpp
\
mathexpr
.
cpp
\
neighborhood_rules
/
arbitraryneighborhoodrule
.
cpp
\
neighborhood_rules
/
arbitraryneighborhoodrule
.
cpp
\
neighborhood_rules
/
margolusNeighborhoodRule
.
cpp
\
automaton
.
cpp
\
automaton
.
cpp
\
gridview
.
cpp
\
gridview
.
cpp
\
neighborhoodDialog
.
cpp
\
neighborhoodDialog
.
cpp
\
...
@@ -55,6 +56,7 @@ HEADERS += \
...
@@ -55,6 +56,7 @@ HEADERS += \
..
/
include
/
automaton
.
hpp
\
..
/
include
/
automaton
.
hpp
\
..
/
include
/
coord
.
hpp
\
..
/
include
/
coord
.
hpp
\
..
/
include
/
neighborhood_rules
/
mooreNeighborhoodRule
.
hpp
\
..
/
include
/
neighborhood_rules
/
mooreNeighborhoodRule
.
hpp
\
..
/
include
/
neighborhood_rules
/
margolusNeighborhoodRule
.
hpp
\
..
/
include
/
savingdialog
.
hpp
\
..
/
include
/
savingdialog
.
hpp
\
..
/
include
/
transition_rules
/
lifegametransition
.
h
\
..
/
include
/
transition_rules
/
lifegametransition
.
h
\
..
/
include
/
neighborhoodrule
.
hpp
\
..
/
include
/
neighborhoodrule
.
hpp
\
...
...
Yann Boucher
@yboucher
mentioned in issue
#82 (closed)
·
Jun 11, 2021
mentioned in issue
#82 (closed)
mentioned in issue #82
Toggle commit list
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