ConwaysLife is a sample application that implements a parallelized Conways Game of Life. This game is a zero-player game that evolves from an initial state with no further input.
You can find the ConwaysLife project at:
- Start | Programs | Embarcadero RAD Studio Berlin | Samples and then navigate to either of the following folders:
- CPP\RTL\Parallel Library\VCL
- Object Pascal\RTL\Parallel Library\VCL
- Subversion Repository:
This sample is an implementation of the Conways Game of Life that shows the performance of the TParallel.For versus the serial running.
In the application interface you have the following controls:
- Parallel checkbox lets you to switch from the serial version (not checked) to the parallel version (checked).
- Start button runs the life generation, Stop resumes the game.
- Clear button cleans the board of cells.
- Re Center focuses the grid board centering both scrollbars.
- Load button allows you to load
.LIFfiles. These files are different starting points for the simulation. They are contained in the
Lifsfolder in the project.
How to Use the Sample
- Navigate to the location given above and open ConwaysLife.dproj or ConwaysLifeCpp.cbproj.
- Select Run > Run to run the application.
- On the application interface:
- Click the Start button (with the Parallel checkbox unchecked).
- Look at the number of
Generations per secondsdisplayed in the interface (these are values of the serial version of the game implementation).
- Click the Stop button.
- Now check the Parallel option and click the Start button again.
- Look again at the number of
Generations per secondsdisplayed and see how this value has now increased.
Note: You can check the CPU performance on the task manager in your computer to see the use that the parallel version does.
- Click again the Stop button.
- Click the Load button and select any
.LIFfile from the \RTL\Parallel Library\Lifs\ folder, for example
- Click again the Start button to see the life generation.
Tip: To visualize the evolution of the game you might Stop, then Re Center and finally Start again the application.
The ConwaysLife project.
The main form that is the user interface for the Conways Game of Life sample.
The container holding source code for the methods used in the ConwaysLifeFMX sample.
The container holding source code for the life engine of the Conways Game of Life.
Each application defines a single class that implements the main form of the application.
- TLifeForm is the main form that handles all controls.
- TLifeEngine implements the different threads for updating generations.
- ELifeEngine implements exceptions for the life engine.
ProcessCellsfunction will run in the serial version of the application (Parallel option unchecked). It will process on one generation at the time.
- The TParallel.For method is implemented to increase the efficiency of the application. It runs having the Parallel option checked. TParallel.For processes a lot of cells of the board simultaneously.