For those unfamiliar with the game, the rules are simple.
You define a grid and initialize each cell to either living or dead.
Then you traverse the grid checkin the surrounding cells.
If the current cell is alive it stays alive as long as 2 or 3 of its
neighboring cells are alive.
If the current cell is dead it can come to life if exactly 3 neighbors are
alive.
This code can take an argument to define the grid size, 20 seemed like a good size for my terminal window.
A few notes on the code...map{sub __;$/=$_;sub _;map{$g[$/][$_]{c}=rand(time)%2;push@{$g[$/][$_] +{n}}, ( \$g[_$/][ $_]{c} =>\$g[__$/][ $_]{c}=>\$g[ $/][_$_]{c}=>\$g[ $/][__ +$_]{c}, \$g[_$/][_$_]{c} =>\$g[_ $/][__$_]{c}=>\$g[__$/][_$_]{c}=>\$g[__$/][__ +$_]{c}, )}(0..$s)}(0..($s=(shift or 15)-1));sub __{(($m=shift)+1)<=$s?$m+1:0} +sub _ { (($m=shift)-1)>=0?$m-1:$s}__;__;while(1){map{$/=$_;map{print$g[$/][$_] +{c}; $u +=$$_ for(@{$g[$/][$_]{n}});$t[$/][$_]{c}=$g[$/][$_]{c};$t[ $/][$_]{c} +=($u==3 ?1:($u !=2?0:($t[$/][$_]{c}==1?1:0)));__;$u=~s _.__;}(0..$s);print"\n" +;}(0 .. $s);print"\n";map{$/=$_; map{$g[$/][$_]{c}=$t[$/][$_]{c}}(0..$s)}(0..$ +s);_;_; __;_;__;_;__;_;__;_;sleep 1}__;_;__;_;_;__;_;__;_;_;__;_;__;_;_;__;_;_ +_;_;__;
Thanks,
Ira,
"So... What do all these little arrows mean?"
~unknown
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: life gets obfuscated
by belg4mit (Prior) on Nov 29, 2001 at 05:39 UTC | |
|
life gets (?:more) obfuscated
by belg4mit (Prior) on Nov 30, 2001 at 02:11 UTC | |
|
Re: life gets obfuscated
by c0d34w4y (Acolyte) on Dec 11, 2001 at 04:18 UTC | |
by c0d34w4y (Acolyte) on Dec 14, 2001 at 04:32 UTC |