DragonRuby Game Toolkit
Postcarts

Conway's Game of Life

cereal2025-02-09 13:15:49 UTC
258/300
w=160
h=90
g=w.times.map{h.times.map{rand<0.1}}
TICK{
bg!0
k=g.map(&:dup)
w.times{|x|h.times{|y|
n=0
-1.upto(1){|i|-1.upto(1){|j|n+=1 if g[(x+i)%w][(y+j)%h]&&(i!=0||j!=0)}}
k[x][y]=(n==3||n==2&&k[x][y])||(n==3&&!k[x][y])
sld!(x,y)if k[x][y]}}
g=k.map(&:dup)}