-- An example of a TerraME model -- This is a simple model that creates a -- random initial distribution of values [1,1000] -- -- Reference: Batty, "Cities and Complexity, pg 38" -- (c) Gilberto Camara, 2007 -- GLOBAL VARIABLES csQ = 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 csQ:load(); CreateMooreNeighbourhood(csQ); csQ:synchronize(); for time = 1,10, 1 do for i, cell in pairs( csQ.cells ) do count = 0; ForEachNeighbour (cell, 0, function (cell, neigh) if (neigh.past.life == 1 and cell ~= neigh ) then count = count + 1 end; end ); -- 1. Any live cell with fewer than two live neighbours dies, as if by loneliness. -- 2. Any live cell with more than three live neighbours dies, as if by overcrowding. -- 3. Any live cell with two or three live neighbours lives, unchanged, to the next generation. -- 4. Any dead cell with exactly three live neighbours comes to life. if (cell.past.life == 1 and count > 3) then cell.life = 0 end; if (cell.past.life == 1 and count < 2) then cell.life = 0 end; if (cell.past.life == 0 and count == 3) then cell.life = 1 end; if (cell.past.life == 1 and (count == 3 or count == 2 )) then cell.life = 1 end; end -- preencher o começo csQ:synchronize(); csQ:save(time,"celulas2000_", {"life"}); end ---- for i, cells ... --- For EachNeighbour....