[GOODIE] StarSqueak Game of Life
Helge Horch
Helge.Horch at munich.netsurf.de
Sat Nov 3 02:15:43 UTC 2001
Folks,
please find attached the promised implementation of Conway's "Game of Life"
in the StarSqueak framework (as mentioned on the "Lots of concurrency" thread).
I have also just published it as a project on Bob's SuperSwiki. Since this
is the first time I've gone through the chore, I'm not sure whether it has
worked out OK or not. I'd be grateful for reports to that end. (It was
published from a 3.1a4332 image.)
As for what is different about this implementation, feel free to skip forward.
---
In case you want to load it manually: You'll need two of the changesets I
posted a couple of minutes ago, before filing in this one. They are:
* StarSqueakFixes.3.cs -- "[FIX] Assorted StarSqueak Fixes"
* StarSqueakEnh.1.cs -- "[ENH] Faster StarSqueak patch variables"
With these under your image's belt, file in this one (StarSqueakLife.12.cs)
and open a StarSqueakLife with
StarSqueakLife new openInWorld
Next, get a menu on that Morph (from the red halo), and keep it up. Maybe
set the scale to 4 (from the menu). Now you can start, stop and step the
Life from the menu.
Note how cells change colour with age, i.e. the number of generations they
survived. They are, as specified in LifeTurtle>>ageColor and LifeTurtle
class>>ageColors, going through
Color showColors: (Color hotColdShades: 100).
You can change this to e.g. the gradient
Color showColors: (Color smoothShades: 50)
but don't forget to zap LifeTurtle's class variable AgeColors (easiest from
a Browser, select LifeTurtle's class declaration and evaluate "AgeColors _
nil").
---
Further fun: Get an Explorer on Life (don't you wish) from the gray halo
("explore morph"), and from its lower pane, send it the messages
self deleteTurtles.
self putForm: Form fromUser at: 5 at 20
Or. Define custom Forms like
form _ Form extent: 37 at 10.
y _ 0.
'
.........................*..........
......................****....*.....
.............*.......****.....*.....
............*.*......*..*.........**
...........*...**....****.........**
**.........*...**.....****..........
**.........*...**........*..........
............*.*.....................
.............*......................'
linesDo: [:line |
line withIndexDo: [:c :x |
c = $.
ifFalse: [form colorAt: x at y put: Color black]].
y _ y+1].
GliderGun _ form
and in the Explorer do
self deleteTurtles.
self putForm: GliderGun at: 20 at 20.
and start.
---
Implementation Notes
LifeTurtles play the role of cells, while patches keep track of neighbor
counts. LifeTurtles keep track of their age, and change color accordingly.
If StarSqueak places more than one LifeTurtle in a patch, the LifeTurtles
will wander to find an empty patch.
There are a lot of Life implementations out there (including Dan's bitblt
wizardry) that are a lot faster. Don't expect 100s of generations per
second, expect more like 5-7 per second. Why? Each "cell" is actually an
object with more state than 1 bit, and birth is handled by a global demon
that examines each cell for birth conditions.
See LifeTurtle>>live for the algorithm that cells follow. This method runs
for each cell during each turn. See StarSqueakLife>>giveBirth for the
demon that creates new cells. That method runs once for each turn.
Questions? Post away.
Enjoy,
Helge
-------------- next part --------------
A non-text attachment was scrubbed...
Name: StarSqueakLife.12.cs.gz
Type: application/octet-stream
Size: 2562 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20011103/69c5fdae/StarSqueakLife.12.cs.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LifeX1.gif
Type: image/gif
Size: 3408 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20011103/69c5fdae/LifeX1.gif
More information about the Squeak-dev
mailing list
|