Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
C
Conway
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Adrian Kosmaczewski
Conway
Commits
8749f8a6
Commit
8749f8a6
authored
Sep 26, 2020
by
Adrian Kosmaczewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made the Python version a bit more readable, and removed unused code
parent
a6a7823d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
69 additions
and
76 deletions
+69
-76
Python/.gitignore
Python/.gitignore
+1
-0
Python/.idea/Conway.iml
Python/.idea/Conway.iml
+3
-3
Python/.idea/misc.xml
Python/.idea/misc.xml
+1
-1
Python/README.adoc
Python/README.adoc
+1
-1
Python/conway/coord.py
Python/conway/coord.py
+0
-8
Python/conway/world.py
Python/conway/world.py
+33
-33
Python/main.py
Python/main.py
+14
-14
Python/tests.py
Python/tests.py
+16
-16
No files found.
Python/.gitignore
View file @
8749f8a6
__pycache__
# Created by https://www.gitignore.io/api/pycharm
# Edit at https://www.gitignore.io/?templates=pycharm
...
...
Python/.idea/Conway.iml
View file @
8749f8a6
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"PYTHON_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
>
<content
url=
"file://$MODULE_DIR$"
>
<excludeFolder
url=
"file://$MODULE_DIR$/venv"
/>
<content
url=
"file://$MODULE_DIR$
/..
"
>
<excludeFolder
url=
"file://$MODULE_DIR$/
../
venv"
/>
</content>
<orderEntry
type=
"jdk"
jdkName=
"Python 3.
7 (Conway
)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 3.
8 (.
)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
\ No newline at end of file
Python/.idea/misc.xml
View file @
8749f8a6
...
...
@@ -3,5 +3,5 @@
<component
name=
"JavaScriptSettings"
>
<option
name=
"languageLevel"
value=
"ES6"
/>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
project-jdk-name=
"Python 3.
7 (Conway
)"
project-jdk-type=
"Python SDK"
/>
<component
name=
"ProjectRootManager"
version=
"2"
project-jdk-name=
"Python 3.
8 (.
)"
project-jdk-type=
"Python SDK"
/>
</project>
\ No newline at end of file
Python/README.adoc
View file @
8749f8a6
= Python
This application is written in Python 3.
7
, and can be run using the `./main.py` command.
This application is written in Python 3.
8
, and can be run using the `./main.py` command.
== Tests
...
...
Python/conway/coord.py
View file @
8749f8a6
...
...
@@ -11,11 +11,3 @@ class Coord:
def
__ne__
(
self
,
other
):
return
not
(
self
==
other
)
def
__str__
(
self
):
return
"%d:%d"
%
(
self
.
x
,
self
.
y
)
@
staticmethod
def
parse
(
str
):
values
=
list
(
map
(
int
,
str
.
split
(
":"
)))
return
Coord
(
values
[
0
],
values
[
1
])
Python/conway/world.py
View file @
8749f8a6
from
.
import
c
ell
from
.
import
c
oord
from
.
cell
import
C
ell
from
.
coord
import
C
oord
class
World
:
def
__init__
(
self
,
size
,
alive_cells
):
...
...
@@ -7,11 +7,11 @@ class World:
self
.
cells
=
{}
for
a
in
range
(
0
,
self
.
size
):
for
b
in
range
(
0
,
self
.
size
):
c
=
coord
.
Coord
(
a
,
b
)
c
=
Coord
(
a
,
b
)
if
c
in
alive_cells
:
self
.
cells
[
c
]
=
cell
.
Cell
.
ALIVE
self
.
cells
[
c
]
=
Cell
.
ALIVE
else
:
self
.
cells
[
c
]
=
cell
.
Cell
.
DEAD
self
.
cells
[
c
]
=
Cell
.
DEAD
def
evolve
(
self
):
alive_cells
=
[]
...
...
@@ -19,10 +19,10 @@ class World:
count
=
0
for
a
in
range
(
-
1
,
2
):
for
b
in
range
(
-
1
,
2
):
current_coord
=
coord
.
Coord
(
key
.
x
+
a
,
key
.
y
+
b
)
if
current_coord
!=
key
and
current_coord
in
self
.
cells
and
self
.
cells
[
current_coord
]
==
cell
.
Cell
.
ALIVE
:
current_coord
=
Coord
(
key
.
x
+
a
,
key
.
y
+
b
)
if
current_coord
!=
key
and
current_coord
in
self
.
cells
and
self
.
cells
[
current_coord
]
==
Cell
.
ALIVE
:
count
+=
1
if
value
==
cell
.
Cell
.
ALIVE
:
if
value
==
Cell
.
ALIVE
:
if
count
==
2
or
count
==
3
:
alive_cells
.
append
(
key
)
else
:
...
...
@@ -47,46 +47,46 @@ class World:
s
+=
"
\n
"
s
+=
(
"%3s|"
%
a
)
for
b
in
range
(
0
,
self
.
size
):
c
=
coord
.
Coord
(
b
,
a
)
c
=
Coord
(
b
,
a
)
s
+=
(
"%s"
%
self
.
cells
[
c
])
s
+=
"
\n
"
return
s
@
staticmethod
def
blinker
(
c
):
return
[
coord
.
Coord
(
c
.
x
,
c
.
y
),
coord
.
Coord
(
c
.
x
+
1
,
c
.
y
),
coord
.
Coord
(
c
.
x
+
2
,
c
.
y
)]
return
[
Coord
(
c
.
x
,
c
.
y
),
Coord
(
c
.
x
+
1
,
c
.
y
),
Coord
(
c
.
x
+
2
,
c
.
y
)]
@
staticmethod
def
beacon
(
c
):
return
[
coord
.
Coord
(
c
.
x
,
c
.
y
),
coord
.
Coord
(
c
.
x
+
1
,
c
.
y
),
coord
.
Coord
(
c
.
x
,
c
.
y
+
1
),
coord
.
Coord
(
c
.
x
+
1
,
c
.
y
+
1
),
coord
.
Coord
(
c
.
x
+
2
,
c
.
y
+
2
),
coord
.
Coord
(
c
.
x
+
3
,
c
.
y
+
2
),
coord
.
Coord
(
c
.
x
+
2
,
c
.
y
+
3
),
coord
.
Coord
(
c
.
x
+
3
,
c
.
y
+
3
)]
return
[
Coord
(
c
.
x
,
c
.
y
),
Coord
(
c
.
x
+
1
,
c
.
y
),
Coord
(
c
.
x
,
c
.
y
+
1
),
Coord
(
c
.
x
+
1
,
c
.
y
+
1
),
Coord
(
c
.
x
+
2
,
c
.
y
+
2
),
Coord
(
c
.
x
+
3
,
c
.
y
+
2
),
Coord
(
c
.
x
+
2
,
c
.
y
+
3
),
Coord
(
c
.
x
+
3
,
c
.
y
+
3
)]
@
staticmethod
def
glider
(
c
):
return
[
coord
.
Coord
(
c
.
x
+
2
,
c
.
y
+
2
),
coord
.
Coord
(
c
.
x
+
1
,
c
.
y
+
2
),
coord
.
Coord
(
c
.
x
,
c
.
y
+
2
),
coord
.
Coord
(
c
.
x
+
2
,
c
.
y
+
1
),
coord
.
Coord
(
c
.
x
+
1
,
c
.
y
)]
return
[
Coord
(
c
.
x
+
2
,
c
.
y
+
2
),
Coord
(
c
.
x
+
1
,
c
.
y
+
2
),
Coord
(
c
.
x
,
c
.
y
+
2
),
Coord
(
c
.
x
+
2
,
c
.
y
+
1
),
Coord
(
c
.
x
+
1
,
c
.
y
)]
@
staticmethod
def
block
(
c
):
return
[
coord
.
Coord
(
c
.
x
,
c
.
y
),
coord
.
Coord
(
c
.
x
+
1
,
c
.
y
),
coord
.
Coord
(
c
.
x
,
c
.
y
+
1
),
coord
.
Coord
(
c
.
x
+
1
,
c
.
y
+
1
)]
return
[
Coord
(
c
.
x
,
c
.
y
),
Coord
(
c
.
x
+
1
,
c
.
y
),
Coord
(
c
.
x
,
c
.
y
+
1
),
Coord
(
c
.
x
+
1
,
c
.
y
+
1
)]
@
staticmethod
def
tub
(
c
):
return
[
coord
.
Coord
(
c
.
x
+
1
,
c
.
y
),
coord
.
Coord
(
c
.
x
,
c
.
y
+
1
),
coord
.
Coord
(
c
.
x
+
2
,
c
.
y
+
1
),
coord
.
Coord
(
c
.
x
+
1
,
c
.
y
+
2
)]
return
[
Coord
(
c
.
x
+
1
,
c
.
y
),
Coord
(
c
.
x
,
c
.
y
+
1
),
Coord
(
c
.
x
+
2
,
c
.
y
+
1
),
Coord
(
c
.
x
+
1
,
c
.
y
+
2
)]
Python/main.py
View file @
8749f8a6
...
...
@@ -3,30 +3,30 @@
import
os
from
signal
import
signal
,
SIGINT
from
time
import
sleep
from
conway
import
coor
d
from
conway
import
worl
d
from
conway
.world
import
Worl
d
from
conway
.coord
import
Coor
d
def
handler
(
signal_received
,
frame
):
os
.
system
(
'clear'
)
os
.
system
(
"clear"
)
exit
(
0
)
blinker
=
world
.
World
.
blinker
(
coord
.
Coord
(
0
,
1
))
beacon
=
world
.
World
.
beacon
(
coord
.
Coord
(
10
,
10
))
glider
=
world
.
World
.
glider
(
coord
.
Coord
(
4
,
5
))
block1
=
world
.
World
.
block
(
coord
.
Coord
(
1
,
10
))
block2
=
world
.
World
.
block
(
coord
.
Coord
(
18
,
3
))
tub
=
world
.
World
.
tub
(
coord
.
Coord
(
6
,
1
))
blinker
=
World
.
blinker
(
Coord
(
0
,
1
))
beacon
=
World
.
beacon
(
Coord
(
10
,
10
))
glider
=
World
.
glider
(
Coord
(
4
,
5
))
block1
=
World
.
block
(
Coord
(
1
,
10
))
block2
=
World
.
block
(
Coord
(
18
,
3
))
tub
=
World
.
tub
(
Coord
(
6
,
1
))
alive_cells
=
blinker
+
beacon
+
glider
+
block1
+
block2
+
tub
w
=
world
.
World
(
30
,
alive_cells
)
w
orld
=
World
(
30
,
alive_cells
)
generation
=
0
if
__name__
==
'__main__'
:
if
__name__
==
"__main__"
:
signal
(
SIGINT
,
handler
)
while
True
:
os
.
system
(
'clear'
)
os
.
system
(
"clear"
)
generation
+=
1
print
(
w
)
print
(
w
orld
)
print
((
"Generation %d"
%
generation
))
sleep
(
0.5
)
w
=
w
.
evolve
()
w
orld
=
world
.
evolve
()
Python/tests.py
View file @
8749f8a6
#!/usr/bin/env python3
import
unittest
from
conway
import
w
orld
from
conway
import
c
oord
from
unittest
import
TestCase
,
main
from
conway
.world
import
W
orld
from
conway
.coord
import
C
oord
class
MyTestCase
(
unittest
.
TestCase
):
class
MyTestCase
(
TestCase
):
def
test_block
(
self
):
alive
=
world
.
World
.
block
(
coord
.
Coord
(
0
,
0
))
original
=
world
.
World
(
5
,
alive
)
alive
=
World
.
block
(
Coord
(
0
,
0
))
original
=
World
(
5
,
alive
)
next_world
=
original
.
evolve
()
self
.
assertEqual
(
next_world
,
original
)
def
test_tub
(
self
):
alive
=
world
.
World
.
tub
(
coord
.
Coord
(
0
,
0
))
original
=
world
.
World
(
5
,
alive
)
alive
=
World
.
tub
(
Coord
(
0
,
0
))
original
=
World
(
5
,
alive
)
next_world
=
original
.
evolve
()
self
.
assertEqual
(
next_world
,
original
)
def
test_blinker
(
self
):
alive
=
world
.
World
.
blinker
(
coord
.
Coord
(
0
,
1
))
original
=
world
.
World
(
3
,
alive
)
alive
=
World
.
blinker
(
Coord
(
0
,
1
))
original
=
World
(
3
,
alive
)
gen1
=
original
.
evolve
()
expected_alive
=
[
coord
.
Coord
(
1
,
0
),
coord
.
Coord
(
1
,
1
),
coord
.
Coord
(
1
,
2
)]
expected
=
world
.
World
(
3
,
expected_alive
)
expected_alive
=
[
Coord
(
1
,
0
),
Coord
(
1
,
1
),
Coord
(
1
,
2
)]
expected
=
World
(
3
,
expected_alive
)
self
.
assertEqual
(
expected
,
gen1
)
gen2
=
gen1
.
evolve
()
self
.
assertEqual
(
original
,
gen2
)
if
__name__
==
'__main__'
:
unittest
.
main
()
if
__name__
==
"__main__"
:
main
()
Write
Preview
Markdown
is supported
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