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
18aeec63
Commit
18aeec63
authored
Sep 13, 2020
by
Adrian Kosmaczewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Style similar to that seen in other apps
parent
35c24ca4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
70 deletions
+27
-70
README.adoc
README.adoc
+1
-1
Smalltalk/cell.st
Smalltalk/cell.st
+3
-7
Smalltalk/coord.st
Smalltalk/coord.st
+3
-6
Smalltalk/main.st
Smalltalk/main.st
+2
-5
Smalltalk/tests.st
Smalltalk/tests.st
+3
-7
Smalltalk/world.st
Smalltalk/world.st
+15
-44
No files found.
README.adoc
View file @
18aeec63
...
...
@@ -44,7 +44,6 @@ FreeBASIC 5 37 4 290
PHP 5 34 11 252
Go 5 42 21 252
Rust 5 32 3 252
Smalltalk 5 44 0 250
Visual Basic .NET 5 32 1 248
C++ 5 35 8 234
...
...
@@ -54,6 +53,7 @@ C# 5 33 1 229
TypeScript 5 28 6 216
Lua 5 28 6 215
Smalltalk 5 41 0 208
Swift 5 33 29 204
Ruby 5 28 1 192
Kotlin 5 26 1 186
...
...
Smalltalk/cell.st
View file @
18aeec63
...
...
@@ -6,12 +6,9 @@ Object subclass: Cell [
|
c
|
c
:=
super
new
.
c
initAlive:
alive
.
^
c
]
^
c
]
initAlive:
alive
[
state
:=
alive
.
]
initAlive:
alive
[
state
:=
alive
.
]
aliveValue
:=
Cell
newAlive:
true
.
deadValue
:=
Cell
newAlive:
false
.
...
...
@@ -19,8 +16,7 @@ Object subclass: Cell [
printOn:
stream
[
state
ifTrue:
[
' x |'
displayOn:
stream
]
ifFalse:
[
' |'
displayOn:
stream
].
]
ifFalse:
[
' |'
displayOn:
stream
]
]
]
Cell
class
extend
[
...
...
Smalltalk/coord.st
View file @
18aeec63
...
...
@@ -6,19 +6,16 @@ Object subclass: Coord [
|
c
|
c
:=
super
new
.
c
initWithX:
x
y:
y
.
^
c
]
^
c
]
initWithX:
xValue
y:
yValue
[
x
:=
xValue
.
y
:=
yValue
.
]
y
:=
yValue
]
printOn:
stream
[
x
displayOn:
stream
.
':'
displayOn:
stream
.
y
displayOn:
stream
.
]
y
displayOn:
stream
]
x
[
^
x
]
...
...
Smalltalk/main.st
View file @
18aeec63
...
...
@@ -25,15 +25,12 @@ Object subclass: Conway [
generation
printNl
.
(
Delay
forMilliseconds:
500
)
wait
.
world
:=
world
evolve
.
]
repeat
]
]
repeat
]
Conway
class
>>
clrscr
[
<
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
.
]
]
(
'%1[H'
%
#(
$<
16r1
B>
)
)
displayNl
]
]
Conway
main
.
Smalltalk/tests.st
View file @
18aeec63
...
...
@@ -10,16 +10,14 @@ TestCase subclass: ConwayTests [
alive
:=
World
block:
(
Coord
newWithX:
0
y:
0
).
original
:=
World
newWithSize:
5
aliveCells:
alive
.
next
:=
original
evolve
.
self
assert:
next
=
original
.
]
self
assert:
next
=
original
]
testTub
[
|
alive
original
next
|
alive
:=
World
tub:
(
Coord
newWithX:
0
y:
0
).
original
:=
World
newWithSize:
5
aliveCells:
alive
.
next
:=
original
evolve
.
self
assert:
next
=
original
.
]
self
assert:
next
=
original
]
testBlinker
[
|
alive
original
gen1
gen2
expectedAlive
expected
|
...
...
@@ -33,9 +31,7 @@ TestCase subclass: ConwayTests [
expected
:=
World
newWithSize:
3
aliveCells:
expectedAlive
.
self
assert:
expected
=
gen1
.
gen2
:=
gen1
evolve
.
self
assert:
original
=
gen2
.
]
]
self
assert:
original
=
gen2
]
]
ConwayTests
suite
run
.
Smalltalk/world.st
View file @
18aeec63
...
...
@@ -6,8 +6,7 @@ Object subclass: World [
|
w
|
w
:=
super
new
.
w
initWithSize:
size
aliveCells:
cells
.
^
w
]
^
w
]
initWithSize:
newSize
aliveCells:
aliveCells
[
|
coord
interval
|
...
...
@@ -20,10 +19,7 @@ Object subclass: World [
coord
:=
Coord
newWithX:
a
y:
b
.
(
aliveCells
includes:
coord
)
ifTrue:
[
cells
at:
coord
put:
Cell
alive
]
ifFalse:
[
cells
at:
coord
put:
Cell
dead
].
]
]
]
ifFalse:
[
cells
at:
coord
put:
Cell
dead
]
]
]
]
evolve
[
|
alive
|
...
...
@@ -39,19 +35,11 @@ Object subclass: World [
(
coord
=
currentCoord
)
ifFalse:
[
(
cells
includesKey:
currentCoord
)
ifTrue:
[
|
currentCell
|
currentCell
:=
cells
at:
currentCoord
.
currentCell
=
Cell
alive
ifTrue:
[
count
:=
count
+
1
]
]
]
]
].
currentCell
=
Cell
alive
ifTrue:
[
count
:=
count
+
1
]
]
]
]
].
cell
=
Cell
alive
ifTrue:
[
(
count
=
2
or:
[
count
=
3
])
ifTrue:
[
alive
add:
coord
].
].
cell
=
Cell
alive
ifTrue:
[
(
count
=
2
or:
[
count
=
3
])
ifTrue:
[
alive
add:
coord
]
].
cell
=
Cell
dead
ifTrue:
[
count
=
3
ifTrue:
[
alive
add:
coord
]
]
].
cell
=
Cell
dead
ifTrue:
[
count
=
3
ifTrue:
[
alive
add:
coord
].
]
].
^
World
newWithSize:
size
aliveCells:
alive
.
]
...
...
@@ -64,34 +52,24 @@ Object subclass: World [
' '
displayOn:
stream
.
interval
do:
[
:
b
|
(
b
printPaddedWith:
Character
space
to:
3
)
displayOn:
stream
.
'|'
displayOn:
stream
.
].
'|'
displayOn:
stream
].
Character
cr
displayOn:
stream
.
Character
lf
displayOn:
stream
.
].
Character
lf
displayOn:
stream
].
(
a
printPaddedWith:
Character
space
to:
3
)
displayOn:
stream
.
'|'
displayOn:
stream
.
interval
do:
[
:
b
|
|
cell coord
|
coord
:=
Coord
newWithX:
b
y:
a
.
cell
:=
cells
at:
coord
.
cell
displayOn:
stream
.
].
cell
displayOn:
stream
].
Character
cr
displayOn:
stream
.
Character
lf
displayOn:
stream
.
]
]
Character
lf
displayOn:
stream
]
]
size
[
^
size
]
cells
[
^
cells
]
=
arg
[
size
=
arg
size
ifFalse:
[
^
false
].
cells
=
arg
cells
ifFalse:
[
^
false
].
^
true
.
]
]
=
arg
[
^
size
=
arg
size
and:
[
cells
=
arg
cells
]
]
]
World
class
extend
[
blinker:
coord
[
...
...
@@ -100,8 +78,7 @@ World class extend [
result
add:
(
Coord
newWithX:
coord
x
y:
coord
y
).
result
add:
(
Coord
newWithX:
coord
x
+
1
y:
coord
y
).
result
add:
(
Coord
newWithX:
coord
x
+
2
y:
coord
y
).
^
result
.
]
^
result
]
beacon:
coord
[
|
result
|
...
...
@@ -114,8 +91,7 @@ World class extend [
result
add:
(
Coord
newWithX:
coord
x
+
3
y:
coord
y
+
2
).
result
add:
(
Coord
newWithX:
coord
x
+
2
y:
coord
y
+
3
).
result
add:
(
Coord
newWithX:
coord
x
+
3
y:
coord
y
+
3
).
^
result
.
]
^
result
]
glider:
coord
[
|
result
|
...
...
@@ -125,8 +101,7 @@ World class extend [
result
add:
(
Coord
newWithX:
coord
x
y:
coord
y
+
2
).
result
add:
(
Coord
newWithX:
coord
x
+
2
y:
coord
y
+
1
).
result
add:
(
Coord
newWithX:
coord
x
+
1
y:
coord
y
).
^
result
.
]
^
result
]
block:
coord
[
|
result
|
...
...
@@ -135,8 +110,7 @@ World class extend [
result
add:
(
Coord
newWithX:
coord
x
+
1
y:
coord
y
).
result
add:
(
Coord
newWithX:
coord
x
y:
coord
y
+
1
).
result
add:
(
Coord
newWithX:
coord
x
+
1
y:
coord
y
+
1
).
^
result
.
]
^
result
]
tub:
coord
[
|
result
|
...
...
@@ -145,7 +119,4 @@ World class extend [
result
add:
(
Coord
newWithX:
coord
x
y:
coord
y
+
1
).
result
add:
(
Coord
newWithX:
coord
x
+
2
y:
coord
y
+
1
).
result
add:
(
Coord
newWithX:
coord
x
+
1
y:
coord
y
+
2
).
^
result
.
]
]
^
result
]
]
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