John Conway's Game of Life in D v1.0
Jim Burnes
jvburnes at gmail.com
Thu Apr 24 15:26:18 PDT 2008
Hey D People...
Here is my first significant effort in D: John Conway's Game of Life.
(http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)
It's not a graphics library or a first person shooter, but you may enjoy it. Hopefully someone might be able to use this as a good example of a simple D program. I've cleaned it up a little, but haven't spit-shined it if you know what I mean.
Here are the features:
- compiled with the latest 'gdc' available in Ubuntu 7.10.
- It uses ncurses for output for that "old school effect". If you want to build and run it you'll need a copy of the 'bcd' C to D header converter. Make sure you install his pre-converted headers for curses. (By the way, could someone update the website and make sure they reference 'bcd' as the new header converter. I wasted a lot of time with the other one.)
- It loads its initial population from a file. Format is <row>,<col> for each
populated cell. One data item per line.
- Upon startup, the initial population is displayed and you can edit it with 'vi' like keys. Check the code for the useful keys. (spacebar to flip a cell on/off. vi movement keys to move.)
- Hit ENTER to start the sim. To pause and edit the current population hit ENTER again.
- To single step the sim just press the space bar. Any other key will advance to the next gen. Spacebar again leaves step mode.
- ESC will exit the sim from run state or edit state.
- It auto adapts its data structures at startup to fit your console size.
- It's only about 9k of source code.
Okay, that's it. If you are amused or pissed off just send me an email 8-)
I'm sure you'll identify some code that I could have done using more appropriate D idioms (like the nested for loops could be foreach).
If you can think of improvements, please feel free to send them in and if they make sense I send an update.
I know it's a toy and doesn't include any generic programming or templating examples, but hey its a start and kind of fun.
Next I want to do an AI neuroevolver so I thought this would be appropriate ;-)
Regards,
Jim Burnes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dlife.d
Type: text/x-dsrc
Size: 9636 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20080424/3f8755c6/attachment.d>
More information about the Digitalmars-d
mailing list