Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- запуск: <прога> <правило>
- -- 6 5 7
- -- 5 8
- -- 6 5 6 7
- -- 5 6 7 8
- -- 5 2 3
- -- 5 2 5
- -- 5 3 5
- -- 5 3 6
- -- 5 3 7
- -- 5 3 8
- -- 5 4
- -- 5 4 7
- -- 5 5 8
- -- 4 9
- local component = require("component")
- local args = require("shell").parse(...)
- local hologram = component.hologram
- local function add(mas,x,y,z,f)
- mas[x] = mas[x] or {}
- mas[x][y] = mas[x][y] or {}
- mas[x][y][z] = f
- end
- local h = {}
- local function testLife(xx,yy,zz,jjj)
- local life = 0
- for x = xx-1, xx+1 do
- for y = yy-1, yy+1, (x == xx and y == yy) and 2 or 1 do
- for z = zz-1, zz+1, (x == xx and y == yy) and 2 or 1 do
- if h[x] and h[x][y] and h[x][y][z] then life = life + 1 end
- --hologram.set(x,y,z,jjj) os.sleep(0.3) -- < >
- end
- end
- end
- return life
- end
- -- Set random pole
- for _ = 1,2500 do
- add(h,math.random(8,40),math.random(8,24),math.random(8,40),true)
- end
- -- Set kub
- -- for x = 16-1, 16+1 do
- -- for y = 16-1, 16+1, (x == 16 or y == 16) and 2 or 1 do
- -- for z = 16-1, 16+1, (x == 16 or y == 16 or z == 16) and 2 or 1 do
- -- add(h,x,y,z,true)
- -- end
- -- end
- -- end
- hologram.clear()
- for x,yz in pairs(h) do
- for y,zz in pairs(yz) do
- for z,fl in pairs(zz) do
- if fl then hologram.set(x,y,z,3) end
- end
- end
- end
- local rules = {}
- for i,v in pairs(args) do
- rules[i] = args[i] and tonumber(args[i])
- end
- rules[1] = rules[1] or 5
- if not rules[2] then
- rules[2] = 6
- rules[3] = 7
- rules[4] = 8
- end
- local function rulesValid(inPut)
- local flag
- for i = 2,4 do
- if not rules[i] then break end
- if inPut == rules[i] then flag = true end
- end
- return flag
- end
- while true do
- os.sleep(0.4)
- local newH, noValid = {}, {}
- for xx,vYZ in pairs(h) do
- for yy,vZ in pairs(vYZ) do
- for zz,out in pairs(vZ) do
- local test = testLife(xx,yy,zz,1)
- if rulesValid(test) then add(newH,xx,yy,zz,true) else hologram.set(xx,yy,zz,0) end
- for x = xx-1, xx+1 do
- for y = yy-1, yy+1, (x == xx and y == yy) and 2 or 1 do
- for z = zz-1, zz+1, (x == xx and y == yy) and 2 or 1 do
- if ( not (noValid[x] and noValid[x][y] and noValid[x][y][z]) ) and ( not (newH[x] and newH[x][y] and newH[x][y][z]) ) and (not(h[x] and h[x][y] and h[x][y][z])) and testLife(x,y,z,3) == rules[1] then
- add(newH,x,y,z,true) hologram.set(x,y,z,3)
- else
- add(noValid,x,y,z,true)
- end
- end
- end
- end
- end
- end
- end
- h = newH
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement