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
b3990f2d
Commit
b3990f2d
authored
6 years ago
by
Dolleans Geoffrey
Browse files
Options
Downloads
Patches
Plain Diff
probleme toutes les cellules meurent
parent
70dcf1c6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
game_of_life/Pygame_GoL.py
+13
-9
13 additions, 9 deletions
game_of_life/Pygame_GoL.py
with
13 additions
and
9 deletions
game_of_life/Pygame_GoL.py
+
13
−
9
View file @
b3990f2d
...
...
@@ -2,6 +2,7 @@ import copy
import
pygame
from
pygame
import
*
import
random
as
rd
import
time
#couleur
RED
=
(
255
,
0
,
0
)
...
...
@@ -27,12 +28,11 @@ def generate(size):
universe
.
append
([])
for
y
in
range
(
size_y
):
#ajoute des cellules dans un état aléatoire à l'univers
universe
[
x
].
append
(
cell
ule
(
rd
.
randint
(
0
,
1
),
x
,
y
))
universe
[
x
].
append
(
cell
(
rd
.
randint
(
0
,
1
),
x
,
y
))
return
universe
def
wrap_around
(
dx
,
dy
,
size
):
"""
Si on sort de l
'
univers on revient de l
'
autre coté
"""
global
size
size_x
,
size_y
=
size
if
dy
>
size_y
-
1
:
dy
=
0
...
...
@@ -44,7 +44,7 @@ def wrap_around(dx, dy, size):
dx
=
size_x
-
1
return
dx
,
dy
def
count_voisin
(
cell
):
def
count_voisin
(
cell
,
universe
):
"""
place le nombre de voisin vivant de la cellule dans cell.voisin
"""
x
,
y
=
cell
.
x
,
cell
.
y
size
=
len
(
universe
),
len
(
universe
[
0
])
...
...
@@ -55,10 +55,9 @@ def count_voisin(cell):
if
universe
[
dx
][
dy
].
etat
==
1
:
cell
.
voisin
+=
1
def
update
():
def
update
(
universe
):
for
x
in
range
(
len
(
universe
)):
for
y
in
range
(
universe
[
0
]):
for
y
in
range
(
len
(
universe
[
0
])
)
:
count_voisin
(
universe
[
x
][
y
],
universe
)
def
decide_colour_nxt_state
(
cell
):
...
...
@@ -87,10 +86,12 @@ def decide_colour_nxt_state(cell):
def
play
():
#initialization
pygame
.
init
()
size
=
input
(
"
entrer la taille de l
'
univers: (x,y)
"
)
size_x
=
int
(
input
(
"
entrer la largeur de l
'
univers
"
))
size_y
=
int
(
input
(
"
entrer la hauteur de l
'
univers
"
))
size
=
size_x
,
size_y
scrn
=
pygame
.
display
.
set_mode
((
500
,
500
))
mainsrf
=
pygame
.
Surface
((
500
,
500
))
mainsrf
.
fill
(
white
)
mainsrf
.
fill
(
WHITE
)
universe
=
generate
(
size
)
#game cycle
while
1
:
...
...
@@ -103,6 +104,9 @@ def play():
for
y
in
range
(
size
[
0
]):
for
x
in
range
(
size
[
1
]):
pygame
.
draw
.
rect
(
mainsrf
,
decide_colour_nxt_state
(
universe
[
x
][
y
]),
(
x
*
10
,
y
*
10
,
10
,
10
))
update
()
update
(
universe
)
scrn
.
blit
(
mainsrf
,
(
0
,
0
))
pygame
.
display
.
update
()
time
.
sleep
(
1
)
if
__name__
==
"
__main__
"
:
play
()
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