Ratings | | Unique User Downloads | | Download Rankings |
Not enough user ratings | | Total: 33 | | All time: 11,057 This week: 99 |
|
Description | | Author |
This package is an implementation of the game of life simulation.
It provides classes that implement a board for the game of life defined by John Horton Conway's simulation of the dynamic of the life of beings that exist in an ecosystem.
The package provides classes that encapsulate the behavior of live cells in the life board game and can move by themselves according to the rules applied in each game iteration.
It can also display the game board on a Web page with the symbols representing the cells appearing in each position of the game board grid. Innovation Award
July 2023
Number 2 |
Game of Life is a concept created by John Horton Conway to define how the life of cells will happen in an ecosystem limited by rules.
The life of the cells can be animated and displayed on a board so the users can see what happens to the cells after each game iteration.
This package implements a PHP version of the Game of Life. The package can render the changes to the life of the cells in a Web page updated by this package on each iteration.
Manuel Lemos |
| |
|
|
Innovation award
Nominee: 5x |
|
Example
<?php declare(strict_types=1);
use App\GameOfLife\Board;
use App\GameOfLife\Config\GameConfig;
use App\GameOfLife\Factory\GridFactory;
use App\GameOfLife\GameOfLife;
use App\GameOfLife\Config\LiveCell;
use App\GameOfLife\NextGenerationIgnoredEdge;
use App\GameOfLife\NextGenerationWrapAroundEdge;
require_once __DIR__ . '/vendor/autoload.php';
/*$liveCells = [
new LiveCell(1, 4),
new LiveCell(2, 3),
new LiveCell(2, 4),
];
*/
//4, 8
//$ignoredEdgesAlgorithm = new NextGenerationIgnoredEdge();
$liveCells = [
new LiveCell(0, 2),
new LiveCell(1, 3),
new LiveCell(2, 1),
new LiveCell(2, 2),
new LiveCell(2, 3),
];
$wrapAroundEdgesAlgorithm = new NextGenerationWrapAroundEdge();
$board = new Board(new GridFactory(...$liveCells), 5, 6);
$iterations = 5;
$gameConfig = new GameConfig(
$board,
$wrapAroundEdgesAlgorithm,
$iterations
);
(new GameOfLife($gameConfig))->start();
|
Details
Game of life exersice solution
Build the image
docker image build --tag terdia07/php-7.4 .
Run th container
docker container run -d --name game_of_life --publish 80:80 --mount type=bind,source="$(pwd)",target=/var/www/html terdia07/php-7.4
Enter the container
docker exec -it game_of_life bash
Install phpunit and setup autoloading by running:
cd /var/www/html && composer install
Run test:
./vendor/bin/phpunit tests --testdox
Visit: http://localhost
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.