-- GLOBAL VARIABLES cs = CellularSpace{ dbType = "ADO", host = "localhost", database = "c:\\TerraME\\Database\\celulas_curso.mdb", user = "", password = "", layer = "celulas2000", theme = "celulas2000", select = {"life"} } -- condicao inicial -- fazer o jogo da vida -- salvar o resultados -- RULES cs:load(); CreateMooreNeighbourhood(cs); for i, cell in pairs( cs.cells ) do cell.life = math.random(0,1); end cs:save(1,"segreg_", {"life"}); cs:synchronize(); for time = 2,500, 1 do for i, cell in pairs( cs.cells ) do whites = 0; ForEachNeighbour (cell, 0, function (cell, neigh) if (neigh.past.life == 1 and cell ~= neigh ) then whites = whites + 1 end; end ); -- 1.White cells change to black if there are five or more black neighbours -- 2.Black cells change to white if there are five or more black neighbours if (cell.past.life == 0 and whites > 4) then cell.life = 1 end; if (cell.past.life == 1 and whites < 4) then cell.life = 0 end; end cs:synchronize(); end cs:save(500,"segreg_", {"life"});