Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Game Of Life
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
cs2021
Game Of Life
Commits
f73a9f79
Commit
f73a9f79
authored
3 years ago
by
Gottfried
Browse files
Options
Downloads
Plain Diff
Merge branch 'Mamdasan' into refractoring-(v0.2)
parents
9460037e
30c976d6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
game_library.py
+20
-3
20 additions, 3 deletions
game_library.py
main.py
+4
-3
4 additions, 3 deletions
main.py
test_gol.py
+12
-7
12 additions, 7 deletions
test_gol.py
with
36 additions
and
13 deletions
game_library.py
+
20
−
3
View file @
f73a9f79
...
@@ -62,7 +62,10 @@ class Simulation:
...
@@ -62,7 +62,10 @@ class Simulation:
fig
,
ax
=
plt
.
subplots
()
fig
,
ax
=
plt
.
subplots
()
self
.
fig
=
fig
self
.
fig
=
fig
self
.
ax
=
ax
self
.
ax
=
ax
#self.p = self.ax.imshow(np.zeros_like(game.board()))
self
.
board_shape
=
game
.
board
().
shape
self
.
p
=
self
.
ax
.
imshow
(
np
.
zeros_like
(
game
.
board
()),
\
cmap
=
plt
.
cm
.
gray_r
,
interpolation
=
'
None
'
,
\
extent
=
[
0
,
self
.
board_shape
[
1
],
0
,
self
.
board_shape
[
0
]])
def
__call__
(
self
,
iterations
:
int
):
def
__call__
(
self
,
iterations
:
int
):
"""
"""
...
@@ -72,14 +75,28 @@ class Simulation:
...
@@ -72,14 +75,28 @@ class Simulation:
iterations (int): number of frames to compute
iterations (int): number of frames to compute
"""
"""
return
anim
.
FuncAnimation
(
self
.
fig
,
a
=
anim
.
FuncAnimation
(
self
.
fig
,
self
.
_render
,
self
.
_render
,
init_func
=
self
.
_init
,
init_func
=
self
.
_init
,
frames
=
iterations
,
frames
=
iterations
,
interval
=
200
)
interval
=
200
)
# Add a title
plt
.
title
(
'
Game Of Life
'
)
# Show grid lines
plt
.
grid
(
which
=
'
both
'
,
linestyle
=
'
--
'
)
plt
.
xticks
(
ticks
=
[
i
for
i
in
range
(
self
.
board_shape
[
0
])],
\
labels
=
[
'
'
for
i
in
range
(
self
.
board_shape
[
0
])])
plt
.
yticks
(
ticks
=
[
i
for
i
in
range
(
self
.
board_shape
[
1
])],
\
labels
=
[
'
'
for
i
in
range
(
self
.
board_shape
[
1
])])
plt
.
show
()
return
a
def
_init
(
self
):
def
_init
(
self
):
self
.
p
=
self
.
ax
.
imshow
(
self
.
game
.
board
())
self
.
p
=
self
.
ax
.
imshow
(
self
.
game
.
board
(),
\
cmap
=
plt
.
cm
.
gray_r
,
interpolation
=
'
None
'
,
\
extent
=
[
0
,
self
.
board_shape
[
1
],
0
,
self
.
board_shape
[
0
]])
return
(
self
.
p
,)
return
(
self
.
p
,)
def
_render
(
self
,
i
):
def
_render
(
self
,
i
):
...
...
This diff is collapsed.
Click to expand it.
main.py
+
4
−
3
View file @
f73a9f79
from
gol_library
import
GameOfLife
from
gol_library
import
GameOfLife
from
game_library
import
CliSimulation
,
Simulation
from
game_library
import
CliSimulation
,
Simulation
import
numpy
as
np
import
numpy
as
np
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
rng
=
np
.
random
.
default_rng
()
rng
=
np
.
random
.
default_rng
()
board
=
rng
.
integers
(
0
,
2
,
size
=
(
1
0
,
1
0
),
dtype
=
int
)
board
=
rng
.
integers
(
0
,
2
,
size
=
(
2
0
,
2
0
),
dtype
=
int
)
gol
=
GameOfLife
(
board
)
gol
=
GameOfLife
(
board
)
#sim = CliSimulation(gol)
sim
=
Simulation
(
gol
)
sim
=
Simulation
(
gol
)
res
=
sim
(
50
)
sim
(
500
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test_gol.py
+
12
−
7
View file @
f73a9f79
...
@@ -21,23 +21,28 @@ def oscillators():
...
@@ -21,23 +21,28 @@ def oscillators():
def
test_gol_still_lifes
():
def
test_gol_still_lifes
():
gol
=
GameOfLife
()
for
l
in
still_lifes
():
for
l
in
still_lifes
():
if
np
.
any
(
l
!=
gol
.
next
(
l
)):
gol
=
GameOfLife
(
l
)
gol
.
update
()
if
not
np
.
all
(
l
==
gol
.
board
()):
assert
False
,
"
Still life was not still.
"
assert
False
,
"
Still life was not still.
"
def
test_gol_oscillators
():
def
test_gol_oscillators
():
gol
=
GameOfLife
()
for
l_i
,
l_o
in
oscillators
():
for
l_i
,
l_o
in
oscillators
():
if
np
.
any
(
l_o
!=
gol
.
next
(
l_i
)):
gol
=
GameOfLife
(
l_i
)
gol
.
update
()
if
not
np
.
all
(
l_o
==
gol
.
board
()):
assert
False
,
"
Oscillators did not work.
"
assert
False
,
"
Oscillators did not work.
"
def
test_gol_benchmark
(
benchmark
):
def
test_gol_benchmark
(
benchmark
):
gol
=
GameOfLife
()
board
=
np
.
ones
((
50
,
50
))
board
=
np
.
ones
((
50
,
50
))
benchmark
(
gol
.
next
,
board
)
def
gol_next
(
board
):
gol
=
GameOfLife
(
board
)
gol
.
update
()
return
gol
.
board
()
benchmark
(
gol_next
,
board
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
test_gol_still_lifes
()
test_gol_still_lifes
()
test_gol_oscillators
()
test_gol_oscillators
()
\ No newline at end of file
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