Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

# Game::Life 0.04

Date Added: October 18, 2010  |  Visits: 1.066

Game::Life - Plays Conways Game of Life. SYNOPSIS use Game::Life; my \$game = new Game::Life( 20 ); my \$starting = [ [ 1, 1, 1 ], [ 1, 0, 0 ], [ 0, 1, 0 ] ]; \$game->place_points( 10, 10, \$starting ); for (1..20) { my \$grid = \$game->get_grid(); foreach ( @\$grid ) { print map { \$_ ? X : . } @\$_; print "n"; } print "nn"; \$game->process(); } Conways Game of Life is a basic example of finding living patterns in rather basic rulesets (see NOTES). The Game of Life takes place on a 2-D rectangular grid, with each grid point being either alive or dead. If a living grid point has 2 or 3 neighbors within the surrounding 8 points, the point will remain alive in the next generation; any fewer or more will kill it. A dead grid point will become alive if there are exactly 3 living neighbors to it. With these simple rules, fascinating structures such as gliders that move across the grid, glider guns that generate these gliders, XOR gates, and others have been found. This module simply provides a way to simulate the Game of Life in Perl. In terms of coordinate systems as used in place_points, toggle_point and other functions, the first coodinate is the vertical direction, 0 being the top of the board, and the second is the horizontal direaction, 0 being the left side of the board. Thus, toggling the point of (3,2) will switch the state of the point in the 4th row and 3rd column. The edges of the board are currently set as "flat"; cells on the edge do not have any neighbors, and thus will fall off the board. Future versions may allow for warp edges (if a cell moves off the left side it reappears on the right side)..

 Requirements: No special requirements Platforms: Linux Keyword: Conways,  Conways Game,  Game,  Game Of Life,  Gamelife,  Grid,  Libraries,  Plays Conways Game,  Point,  Programming Users rating: 0/10