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
70dcf1c6
Commit
70dcf1c6
authored
6 years ago
by
Dolleans Geoffrey
Browse files
Options
Downloads
Patches
Plain Diff
GoL en Pycharm avant redaction main
parent
3e585697
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
+62
-2
62 additions, 2 deletions
game_of_life/Pygame_GoL.py
with
62 additions
and
2 deletions
game_of_life/Pygame_GoL.py
+
62
−
2
View file @
70dcf1c6
...
...
@@ -6,7 +6,7 @@ import random as rd
#couleur
RED
=
(
255
,
0
,
0
)
GREEN
=
(
0
,
255
,
255
)
B
l
ACK
=
(
0
,
0
,
0
)
B
L
ACK
=
(
0
,
0
,
0
)
WHITE
=
(
0
,
0
,
0
)
#création de la classe cellule
...
...
@@ -27,10 +27,12 @@ def generate(size):
universe
.
append
([])
for
y
in
range
(
size_y
):
#ajoute des cellules dans un état aléatoire à l'univers
universe
[
x
].
append
(
cellule
(
rd
.
randint
(
0
,
1
),
x
,
y
)
universe
[
x
].
append
(
cellule
(
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
...
...
@@ -45,4 +47,62 @@ def wrap_around(dx, dy, size):
def
count_voisin
(
cell
):
"""
place le nombre de voisin vivant de la cellule dans cell.voisin
"""
x
,
y
=
cell
.
x
,
cell
.
y
size
=
len
(
universe
),
len
(
universe
[
0
])
for
i
in
range
(
-
1
,
2
):
for
j
in
range
(
-
1
,
2
):
if
i
!=
0
and
j
!=
0
:
dx
,
dy
=
wrap_around
(
x
+
i
,
y
+
j
,
size
)
if
universe
[
dx
][
dy
].
etat
==
1
:
cell
.
voisin
+=
1
def
update
():
for
x
in
range
(
len
(
universe
)):
for
y
in
range
(
universe
[
0
]):
count_voisin
(
universe
[
x
][
y
],
universe
)
def
decide_colour_nxt_state
(
cell
):
"""
change l
'
état de la cellule si nécessaire et renvoie la couleur qui la rpz
"""
if
cell
.
etat
:
if
cell
.
voisin
==
2
or
cell
.
voisin
==
3
:
"
la cellule survie, on reset le nombre de voisin vivant
"
cell
.
voisin
=
0
return
BLACK
else
:
"
la cellule meurt
"
cell
.
voisin
=
0
cell
.
etat
=
0
return
RED
else
:
if
cell
.
voisin
==
3
:
"
une cellule nait
"
cell
.
voisin
=
0
cell
.
etat
=
1
return
GREEN
else
:
cell
.
voisin
=
0
return
WHITE
#main game function
def
play
():
#initialization
pygame
.
init
()
size
=
input
(
"
entrer la taille de l
'
univers: (x,y)
"
)
scrn
=
pygame
.
display
.
set_mode
((
500
,
500
))
mainsrf
=
pygame
.
Surface
((
500
,
500
))
mainsrf
.
fill
(
white
)
universe
=
generate
(
size
)
#game cycle
while
1
:
#tracking quitting
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
QUIT
:
pygame
.
quit
()
sys
.
exit
()
#drawing
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
()
scrn
.
blit
(
mainsrf
,
(
0
,
0
))
pygame
.
display
.
update
()
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