about summary refs log blame commit diff stats
path: root/examples/plugin_new_sorting_method.py
blob: d294067e6baa6c5988b94697d6131021dbc650d5 (plain) (tree)
cols then count = count + board[nx][ny] end end end end return count end local nextBoard = deepcopy(board) for x = 1, rows do for y = 1, cols do local liveNeighbors = countLiveNeighbors(board, x, y) if board[x][y] == 1 and (liveNeighbors < 2 or liveNeighbors > 3) then nextBoard[x][y] = 0 elseif board[x][y] == 0 and liveNeighbors == 3 then nextBoard[x][y] = 1 end end end return nextBoard end local function printBoard(board) io.write("\27[2J\27[H") -- clear console for _, row in ipairs(board) do for _, cell in ipairs(row) do io.write(cell == 1 and "1 " or "0 ") end io.write("\n") end end local function runGame(initialBoard, generations) local board = initialBoard for i = 1, generations do printBoard(board) board = getNextState(board) os.execute("sleep 0.5") -- Wait 0.5 seconds between generations end end runGame(initialBoard, 10)