Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Coding Week Gol Dolleans Boujerfaoui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Boujerfaoui Yassine
Coding Week Gol Dolleans Boujerfaoui
Commits
f81f6580
Commit
f81f6580
authored
6 years ago
by
Boujerfaoui Yassine
Browse files
Options
Downloads
Plain Diff
Finalisation de la fonction simulate
parents
52d40b53
20640272
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
game_of_life/GoL_simulate.py
+25
-22
25 additions, 22 deletions
game_of_life/GoL_simulate.py
game_of_life/add_seed.py
+11
-7
11 additions, 7 deletions
game_of_life/add_seed.py
game_of_life/generation.py
+4
-5
4 additions, 5 deletions
game_of_life/generation.py
with
40 additions
and
34 deletions
game_of_life/GoL_simulate.py
+
25
−
22
View file @
f81f6580
...
...
@@ -11,32 +11,35 @@ def simulate(size, type_seed, iterations):
#Création de l'univers et ajout de la graine
universe
=
generate_universe
(
size
)
seed
=
create_seed
(
type_seed
)
print
(
seed
)
#Placement aléatoire de la graine
x_start
=
rd
.
randint
(
0
,
size
[
0
]
-
len
(
seed
))
y_start
=
rd
.
randint
(
0
,
size
[
1
]
-
len
(
seed
[
0
]))
universe
=
add_seed_to_universe
(
seed
,
universe
,
x_start
,
y_start
)
print
(
universe
)
fig
=
plt
.
figure
()
ax
=
plt
.
axes
(
xlim
=
(
-
1
,
size
[
1
]
+
1
),
ylim
=
(
-
1
,
size
[
0
]
+
1
))
plt
.
gca
().
invert_yaxis
()
line
,
=
ax
.
plot
([],[],
lw
=
2
)
def
init
()
:
line
.
save_data
([],[])
return
line
list_universe
=
[
universe
]
for
n
in
range
(
iterations
):
list_universe
.
append
(
generation
(
list_universe
[
-
1
]))
try
:
x_start
=
rd
.
randint
(
0
,
size
[
0
]
-
len
(
seed
))
y_start
=
rd
.
randint
(
0
,
size
[
1
]
-
len
(
seed
[
0
]))
except
:
print
(
"
la graine est trop grande pour l
'
univers
"
)
plt
.
imshow
(
universe
)
fig
=
plt
.
figure
()
im
=
plt
.
imshow
(
universe
,
cmap
=
"
Greys
"
,
animated
=
True
)
def
animate
(
i
):
universe
=
list_universe
[
i
]
for
y
in
range
(
size
[
0
]):
for
x
in
range
(
size
[
1
]):
if
universe
[
y
][
x
]
==
1
:
plt
.
fill
([
x
,
x
+
1
,
x
+
1
,
x
],[
y
,
y
,
y
-
1
,
y
-
1
],
"
k
"
)
line
.
set_data
(
x
,
y
)
return
line
,
ani
=
animation
.
FuncAnimation
(
fig
,
animate
,
init_func
=
init
,
frames
=
iterations
,
blit
=
True
,
interval
=
20
,
repeat
=
False
)
universe
=
im
.
get_array
()
im
.
set_array
(
generation
(
universe
))
return
im
,
anim
=
animation
.
FuncAnimation
(
fig
,
animate
,
interval
=
500
,
frames
=
iterations
,
blit
=
True
)
plt
.
show
()
simulate
((
6
,
6
),
"
beacon
"
,
20
)
simulate
((
6
,
6
),
"
beacon
"
,
10
)
def
main
():
x
=
int
(
input
(
"
Entrer la largeur de l
'
univers
"
))
y
=
int
(
input
(
"
Entrer la hauteur de l
'
univers
"
))
type_seed
=
input
(
"
Entrer le type de graine
"
)
iterations
=
int
(
input
(
"
Entrer le nombre d
'
itérations désiré
"
))
simulate
((
x
,
y
),
type_seed
,
iterations
)
if
__name__
==
"
__main__
"
:
main
()
This diff is collapsed.
Click to expand it.
game_of_life/add_seed.py
+
11
−
7
View file @
f81f6580
...
...
@@ -46,10 +46,11 @@ seeds = {
def
create_seed
(
type_seed
):
"
Renvoie une graine du type indiqué
"
if
type_seed
in
seeds
:
return
seeds
[
type_seed
]
else
:
print
(
"
graine inconnue
"
)
try
:
seed
=
seeds
[
type_seed
]
except
:
print
(
"
Ce type de graine est inconnu
"
)
return
seed
def
add_seed_to_universe
(
seed
,
universe
,
x_start
,
y_start
):
...
...
@@ -57,9 +58,12 @@ def add_seed_to_universe(seed, universe, x_start, y_start):
size_seed
=
(
len
(
seed
),
len
(
seed
[
0
]))
if
size_seed
[
0
]
>
len
(
universe
)
or
size_seed
[
1
]
>
len
(
universe
[
0
]):
print
(
"
la graine est trop grande
"
)
for
x
in
range
(
size_seed
[
0
]):
for
y
in
range
(
size_seed
[
1
]):
universe
[
x_start
+
x
][
y_start
+
y
]
=
seed
[
x
][
y
]
try
:
for
x
in
range
(
size_seed
[
0
]):
for
y
in
range
(
size_seed
[
1
]):
universe
[
x_start
+
x
][
y_start
+
y
]
=
seed
[
x
][
y
]
except
:
print
(
"
la graine est trop grande
"
)
return
universe
...
...
This diff is collapsed.
Click to expand it.
game_of_life/generation.py
+
4
−
5
View file @
f81f6580
...
...
@@ -4,14 +4,13 @@ import numpy as np
def
generation
(
univers
):
"
Applique les règles du jeu de la vie à chaque cellule et renvoie l
'
univers à la génération n+1
"
size
=
len
(
univers
),
len
(
univers
[
0
])
new_univers
=
np
.
zeros
(
size
)
new_univers
e
=
np
.
zeros
(
size
)
for
x
in
range
(
size
[
0
]):
for
y
in
range
(
size
[
1
]):
if
univers
[
x
][
y
]
==
1
:
new_univers
[
x
][
y
]
=
survival
(
univers
,
(
x
,
y
))
new_univers
e
[
x
][
y
]
=
survival
(
univers
,
(
x
,
y
))
else
:
new_univers
[
x
][
y
]
=
naissance
(
univers
,
(
x
,
y
))
return
new_univers
new_universe
[
x
][
y
]
=
naissance
(
univers
,
(
x
,
y
))
return
new_universe
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment