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
16541ead
Commit
16541ead
authored
Sep 13, 2020
by
Adrian Kosmaczewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified to the maximum
parent
18aeec63
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
10 additions
and
15 deletions
+10
-15
README.adoc
README.adoc
+1
-1
Smalltalk/cell.st
Smalltalk/cell.st
+2
-5
Smalltalk/coord.st
Smalltalk/coord.st
+1
-3
Smalltalk/main.st
Smalltalk/main.st
+2
-3
Smalltalk/tests.st
Smalltalk/tests.st
+3
-1
Smalltalk/world.st
Smalltalk/world.st
+1
-2
No files found.
README.adoc
View file @
16541ead
...
...
@@ -53,7 +53,7 @@ C# 5 33 1 229
TypeScript 5 28 6 216
Lua 5 28 6 215
Smalltalk 5
41 0 208
Smalltalk 5
37 0 207
Swift 5 33 29 204
Ruby 5 28 1 192
Kotlin 5 26 1 186
...
...
Smalltalk/cell.st
View file @
16541ead
...
...
@@ -16,11 +16,8 @@ Object subclass: Cell [
printOn:
stream
[
state
ifTrue:
[
' x |'
displayOn:
stream
]
ifFalse:
[
' |'
displayOn:
stream
]
]
]
ifFalse:
[
' |'
displayOn:
stream
]
]
]
Cell
class
extend
[
alive
[
^
aliveValue
]
dead
[
^
deadValue
]
]
dead
[
^
deadValue
]
]
Smalltalk/coord.st
View file @
16541ead
...
...
@@ -23,6 +23,4 @@ Object subclass: Coord [
=
arg
[
^
x
=
arg
x
and:
[
y
=
arg
y
]
]
hash
[
^
(
self
displayString
hash
)
]
]
hash
[
^
self
displayString
hash
]
]
Smalltalk/main.st
View file @
16541ead
...
...
@@ -18,7 +18,7 @@ Object subclass: Conway [
world
:=
World
newWithSize:
30
aliveCells:
cells
.
generation
:=
0
.
[
Conway
cl
rscr
.
Conway
cl
earScreen
.
generation
:=
generation
+
1
.
world
printNl
.
'Generation '
display
.
...
...
@@ -27,10 +27,9 @@ Object subclass: Conway [
world
:=
world
evolve
.
]
repeat
]
Conway
class
>>
cl
rscr
[
Conway
class
>>
cl
earScreen
[
<
comment:
'I clear the screen, courtesy of https://stackoverflow.com/a/24833963 and https://stackoverflow.com/a/37778152/133764'
>
(
'%1[2J'
%
#(
$<
16r1
B>
)
)
displayNl
.
(
'%1[H'
%
#(
$<
16r1
B>
)
)
displayNl
]
]
Conway
main
.
Smalltalk/tests.st
View file @
16541ead
...
...
@@ -7,6 +7,7 @@ FileStream fileIn: 'world.st'.
TestCase
subclass:
ConwayTests
[
testBlock
[
|
alive
original
next
|
'testBlock'
displayNl
.
alive
:=
World
block:
(
Coord
newWithX:
0
y:
0
).
original
:=
World
newWithSize:
5
aliveCells:
alive
.
next
:=
original
evolve
.
...
...
@@ -14,6 +15,7 @@ TestCase subclass: ConwayTests [
testTub
[
|
alive
original
next
|
'testTub'
displayNl
.
alive
:=
World
tub:
(
Coord
newWithX:
0
y:
0
).
original
:=
World
newWithSize:
5
aliveCells:
alive
.
next
:=
original
evolve
.
...
...
@@ -21,6 +23,7 @@ TestCase subclass: ConwayTests [
testBlinker
[
|
alive
original
gen1
gen2
expectedAlive
expected
|
'testBlinker'
displayNl
.
alive
:=
World
blinker:
(
Coord
newWithX:
0
y:
1
).
original
:=
World
newWithSize:
3
aliveCells:
alive
.
gen1
:=
original
evolve
.
...
...
@@ -34,4 +37,3 @@ TestCase subclass: ConwayTests [
self
assert:
original
=
gen2
]
]
ConwayTests
suite
run
.
Smalltalk/world.st
View file @
16541ead
...
...
@@ -40,8 +40,7 @@ Object subclass: World [
cell
=
Cell
alive
ifTrue:
[
(
count
=
2
or:
[
count
=
3
])
ifTrue:
[
alive
add:
coord
]
].
cell
=
Cell
dead
ifTrue:
[
count
=
3
ifTrue:
[
alive
add:
coord
]
]
].
^
World
newWithSize:
size
aliveCells:
alive
.
]
^
World
newWithSize:
size
aliveCells:
alive
]
printOn:
stream
[
|
interval
|
...
...
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