From a90c3ab3460b2d8f8952e6a732e6a7bf846aba37 Mon Sep 17 00:00:00 2001 From: Pavel Marychev Date: Tue, 3 Aug 2021 22:31:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BA=D0=BE=D0=BD=D1=87=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=83=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=B4=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ch11/model.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ch11/model.py b/ch11/model.py index ad5a30b..194e07c 100644 --- a/ch11/model.py +++ b/ch11/model.py @@ -1,19 +1,29 @@ +import random + height = 100 width = 100 +def randomize(grid, width, height): + for i in range(0, height): + for j in range(0, width): + grid[i][j] = random.randint(0, 1) + grid_model = [0] * height +next_grid_model = [0] * height for i in range(height): grid_model[i] = [0] * width + next_grid_model[i] = [0] * width +randomize(grid_model, width, height) def next_gen(): - global grid_model + global grid_model, next_grid_model for i in range(0, height): for j in range(0, width): cell = 0 - print('Проверяем клетку', i, j) + # print('Проверяем клетку', i, j) count = count_neighbors(grid_model, i, j) if grid_model[i][j] == 0: @@ -22,6 +32,11 @@ def next_gen(): elif grid_model[i][j] == 1: if count == 2 or count == 3: cell = 1 + next_grid_model[i][j] = cell + # print('Новое значение:', next_grid_model[i][j]) + temp = grid_model + grid_model = next_grid_model + next_grid_model = temp def count_neighbors(grid, row, col):