Begin File: life.tgz Description: The game of life (Conway's game) Keywords: Photon - Game Version: 1.0.B Entered-date: August-06-1998 Author: Oliver Singla (omsingla@qnx.com) Ported-by: / Original-site: / Copying-policy: Freeware. Supplemental: Description of the game. 1) Presentation This free software implements the game of life running under QNX and Photon 1.12. The game is interesting by itself, but this software can also be used as example of many programming features of Photon 1.12, using Phab (fast drawing of bitmaps and images, shared memory, drag, etc.). There is also some some functions coded in assembler (386). 2) Standard rules of the game In the game of life, cells are living on a large checkerboard and die and reproduce according to simple genetic rules. First note that each cell of the checkerboard has eight neighbors, four adjacent orthogonally, four adjacent diagonally. The standard rules are: Survivals: Every cell with 2 or 3 neighbors survives for the next generation. Deaths: Each cell with 4 or more neighbors dies from overpopulation. Each cell with 1 or nore neighbors dies from isolation. Births: Each empty cell adjacent to exactly neighbors is a birth cell. All births and deaths occur simultaneous. Together they constitue a single generation. Here is a single example (see the help into the game to see births and deaths): [This is my prefered population. She deads at gen #167] Gen #0 Gen #1 Gen #2 Gen #3 Gen #4 ......... ......... ......... ...o..... ..ooo.... ......... ...o..... ..ooo.... ..ooo.... ..ooo.... ..ooo.... ..ooo.... .o...o... .o...o... .o...o... ..o..o... .oo.oo... .oo.oo... .oo.oo... .oo.oo... ..o...o.. ......... ......... ......... ......... Gen #27 Gen #80 ..........o.......... ..............o.............. .........ooo......... ..............o.............. ........o...o........ .ooo..oo......o......oo..ooo. ..........o.......... o...o..o.............o..o...o ......o...o...o...... o......o.............o......o .oo...o.......o...oo. o.....oo.oo.......oo.oo.....o .oo...o.ooooo.o...oo. .o...o..o.o..ooo..o.o..o...o. o......o.ooo.o......o ...o.o....o..o.o..o....o.o... .oo...............oo. .....o...ooooo.ooooo...o..... .ooooo.........ooooo. ..oo.ooooo..oo.oo..ooooo.oo.. .....o.........o..... .o..oooo....o...o....oooo..o. ....o..oo...oo..o.... .o..o...o..o.....o..o...o..o. ....oo.oo...oo.oo.... .o.o.....o.o.....o.o.....o.o. .....o..o...o..o..... ........oo.........oo........ ......oo.....oo...... ........ooo..o.o..ooo........ .............o.o............. ..........o..o.o..o.......... ...........ooo.ooo........... ..........o.o...o.o.......... ...........o.....o........... This example of life ends at generation #162 with the next one: .......................o....................... .......................o....................... .......................o....................... ......oo...............................oo...... ......oo...............................oo...... ..........oo.......................oo.......... ..........oo.......................oo.......... ............................................... ............................................... ............................................... ............................................... ............................................... ............................................... ............................................... ............................................... ooo.........................................ooo ............................................... ....o.....................................o.... ....o.....................................o.... ....o.....................................o.... ............................................... ............................................... ............................................... ............................................... ............................................... ............................................... ............................................... .......oo.............................oo....... ......o..o........oo.......oo........o..o...... ......o..o........oo.......oo........o..o...... .......oo.............................oo....... 3) Highlights of this software - Life field is 800x600. There are 3 main windows: * one is the field where cells evolve (this window is resizable) * one is a zoom onto the field and then enable to enter a population (this window is also resizable) * one is the status (population, births, deaths, rules, etc.). - Generations are computed by an assembler coded function (about 150 msec on my P150) which checks all the 800x600 field. It takes 17 sec. on my P150 to compute *and* draw the generation given in example (generation 0 to 167). - The software uses *both*: * a widget bitmap (two in fact) for the display (computation is made directly inside the bitmap data), so space used is only 60,000 bytes by generation. * but also PgDrawImagemx for fast drawing. - The software computes cycling generations up to backward, where is a parametrable value ( is only limited by available memory). For example: = 100 (100 x 60,000 is just 6Mb in memory). - It's possible to 'undo' (back previous generation), to generations backward. - Ability to Save/Load generations to/from disk. - There is an option in the game to help to find interesting generations by building random populations. - The rules of the game of life are available from the game. - Ability to define new life rules. In the standard rules, there is a birth into an empty cell which has 3 neighbors. There is a death if the living cell has less than 2 neighbors or more than 3. You will be able to change these rules, and also you will be able to use probabilities (in %). - Graphics chart of the evolution of the generations (population, births, deaths). 4) Todo list (work in progress) - Probabilities are not yet used in non standard rules. - Printing. - Ability to save extra-informations (notes, graphics chart) into a file, attached to a population. 5) Installation To install the archive: gzip -cd life.tgz | pax -vr I suggest to install into: /usr/photon/apps/life but this is not mandatory. 6) OS/Photon/Compiler versions The game has been successfully been tested under QNX 4.23-24, Photon 1.12-13 and compiled with Watcom C Compiler v10.6-7 The executable into the archive is compiled with photon 1.13 (slib). It does *not* run under photon 1.10 or 1.11. The main reason is that the PxConfig functions are used and were introduced with Photon 1.12 The software has been tested with the next screen resolutions: - 640x480 - 800x600 - 1024x768 - 1280x1024 The 1st time the software is run (life.ini not found), it adapts the size of the main windows (which are scrollable) to the screen size. 7) Bugs, Improvements, Questions: 0) Please email-me your remarks ! 1) When the zoom window is shrunk, I do not always receive the event Pt_CB_RESIZE, so redraw is not done. 2) I know how to change the state of a given menu item with ApModifyItemState, but how about get the state ? (Now I update a global variable on the callback.) 8) Note on a Previous version A previous version of this software which was distributed was not running properly on main systems (QNX 4.23 and QNX 4,24). I has a bug inside the assembler function (a variable stored into the code segment), and I was running Proc32 v4.22 (the last which was able to handle Rundos). This old version of the Process Manager had a poor memory protection and was consequently insensible to this bug. Proc32 4.23 and later are smart enought to detect a memory violation in such case. 9) Bibliography: - 'What do do after you hit return', PCC, 1979 Have Fun ! Oliver Singla omsingla@qnx.com http://www.qnx.com/~omsingla End