Commit 16541ead authored by Adrian Kosmaczewski's avatar Adrian Kosmaczewski

Simplified to the maximum

parent 18aeec63
......@@ -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
......
......@@ -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 ] ]
......@@ -23,6 +23,4 @@ Object subclass: Coord [
= arg [ ^ x = arg x and: [ y = arg y ] ]
hash [ ^ (self displayString hash) ]
]
hash [ ^ self displayString hash ] ]
......@@ -18,7 +18,7 @@ Object subclass: Conway [
world := World newWithSize:30 aliveCells:cells.
generation := 0.
[
Conway clrscr.
Conway clearScreen.
generation := generation + 1.
world printNl.
'Generation ' display.
......@@ -27,10 +27,9 @@ Object subclass: Conway [
world := world evolve.
] repeat ]
Conway class >> clrscr [
Conway class >> clearScreen [
<comment: 'I clear the screen, courtesy of https://stackoverflow.com/a/24833963 and https://stackoverflow.com/a/37778152/133764'>
('%1[2J' % #($<16r1B>)) displayNl.
('%1[H' % #($<16r1B>)) displayNl ] ]
Conway main.
......@@ -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.
......@@ -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 |
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment