とりあえず定番から、
以下にソースも載せとく
JavaScript版と比べてみると、わりとそのままだなってのがわかると思う
ar={}
function _init()
cls()
for i=0,31 do
ar[i] = {}
for j=0,31 do
ar[i][j] = flr(rnd(2))
end
end
end
function lput(x,y,c,f)
xx = x*4
yy = y*4
if f==1 then
rectfill(xx,yy,xx+4,yy+4,c)
else
rect(xx,yy,xx+4,yy+4,c)
end
end
function copybuff()
for i=1,30 do
ar[i][0] = ar[i][30]
ar[i][31] = ar[i][1]
end
for j=1,30 do
ar[0][j] = ar[30][j]
ar[31][j] = ar[1][j]
end
ar[0][0] = ar[30][30]
ar[31][31] = ar[1][1]
ar[0][31] = ar[30][1]
ar[31][0] = ar[1][30]
end
function deadoralive()
br = {}
for i=0,31 do
br[i] = {}
for j=0,31 do
br[i][j] = ar[i][j]
end
end
for i=1,30 do
br[i] = {}
for j=0,31 do
br[i][j] = ar[i][j]
end
end
for i=1,30 do
for j=1,30 do
cnt = br[i-1][j-1] + br[i][j-1] + br[i+1][j-1]
+ br[i-1][j ] + br[i+1][j ]
+ br[i-1][j+1] + br[i][j+1] + br[i+1][j+1]
if br[i][j]==1 and (cnt==2 or cnt==3) then
elseif br[i][j]==0 and cnt==2 then
elseif br[i][j]==0 and cnt==3 then
ar[i][j] = 1
else
ar[i][j] = 0
end
end
end
end
function draw()
for i=1,30 do
for j=1,30 do
lput(i,j,1,1)
if ar[i][j]==1 then
lput(i,j,7,1)
else
lput(i,j,2,0)
end
end
end
end
function _draw()
copybuff()
deadoralive()
draw()
end
0 件のコメント:
コメントを投稿