PHP Classes

Conway's Game of Life PHP: Implementation of the game of life simulation

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 33 All time: 11,057 This week: 99Up
Version License PHP version Categories
game-of-life-php 1.0.0MIT/X Consortium ...7Games, Artificial intelligence, PHP 7
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
PHP Programming Innovation award nominee
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
Picture of Ogbemudia Osayawe
  Performance   Level  
Name: Ogbemudia Osayawe <contact>
Classes: 9 packages by
Country: Germany Germany
Age: 41
All time rank: 2885172 in Germany Germany
Week rank: 197 Up11 in Germany Germany Up
Innovation award
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

Build Status License: MIT

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





  Files folder image Files (27)  
File Role Description
Files folder image.github (1 directory)
Files folder imagedocker (4 files)
Files folder imagesrc (1 directory)
Files folder imagetests (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file Dockerfile Data Auxiliary data
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (27)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (27)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file ci.yml Data Auxiliary data

  Files folder image Files (27)  /  docker  
File Role Description
  Accessible without login Plain text file default Data Auxiliary data
  Accessible without login Plain text file init.sh Data Auxiliary data
  Accessible without login Plain text file php-fpm.conf Data Auxiliary data
  Accessible without login Plain text file supervisord.conf Data Auxiliary data

  Files folder image Files (27)  /  src  
File Role Description
Files folder imageGameOfLife (10 files, 3 directories)

  Files folder image Files (27)  /  src  /  GameOfLife  
File Role Description
Files folder imageConfig (2 files)
Files folder imageFactory (1 file)
Files folder imageValueObjects (1 file)
  Plain text file Board.php Class Class source
  Plain text file Cell.php Class Class source
  Plain text file GameOfLife.php Class Class source
  Plain text file LiveNeighbourFinder.php Class Class source
  Plain text file LiveNeighbourFinderIgnoreEdge.php Class Class source
  Plain text file LiveNeighbourFinderWrapAroundEdge.php Class Class source
  Plain text file NextGenerationIgnoredEdge.php Class Class source
  Plain text file NextGenerationInterface.php Class Class source
  Plain text file NextGenerationWrapAroundEdge.php Class Class source
  Plain text file RuleApplier.php Class Class source

  Files folder image Files (27)  /  src  /  GameOfLife  /  Config  
File Role Description
  Plain text file GameConfig.php Class Class source
  Plain text file LiveCell.php Class Class source

  Files folder image Files (27)  /  src  /  GameOfLife  /  Factory  
File Role Description
  Plain text file GridFactory.php Class Class source

  Files folder image Files (27)  /  src  /  GameOfLife  /  ValueObjects  
File Role Description
  Plain text file CellState.php Class Class source

  Files folder image Files (27)  /  tests  
File Role Description
Files folder imageGameOfLife (3 files)

  Files folder image Files (27)  /  tests  /  GameOfLife  
File Role Description
  Plain text file GridFactoryTest.php Class Class source
  Plain text file LiveNeighbourFinderTest.php Class Class source
  Plain text file NextGenerationInterfaceTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:33
This week:0
All time:11,057
This week:99Up