ConwaysLifeFMX 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 ConwaysLifeFMX project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to either of the following folders:
CPP\Multi-Device Samples\Parallel Library\FMX
Object Pascal\RTL\Parallel Library\FMX
Object Pascal\Multi-Device Samples\Parallel Library\FMX
- 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 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 ConwaysLifeFMX.dproj or ConwaysLifeFMXCpp.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 FireMonkey 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 processrs a lot of cells of the board simultaneously.