def test_rules_6(): life.setup(3, "empty", "strict_border") start_grid = [[0, 1, 1], [0, 0, 1], [0, 0, 0]] res_grid = np.array(life.make_step(start_grid)) assert np.all(np.argwhere(res_grid == 1) == \ [[0, 1], [0, 2], [1, 1], [1, 2]])
def perform_single_test(side_size, processes_num): random.seed(1) grid = life.setup(side_size, "random", "strict_border", multiprocessing_const=processes_num) i = 0 grid_old = None grid_old_old = None start = time.time() while True: if grid_old: grid_old_old = deepcopy(grid_old) grid_old = deepcopy(grid) grid = life.make_step(grid) if grid_old and grid_old_old: if life._check_empty(grid) or \ life._check_stable(grid, grid_old, grid_old_old): # print("Game ended!") break i += 1 end = time.time() print(f"Game: side: {side_size}, processes: {processes_num}, time: {end-start}") return end-start
def test_rules_1(): life.setup(3, "empty", "strict_border") start_grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]] res_grid = life.make_step(start_grid) assert np.all((np.array(res_grid) == 0))
from modules import life from modules.visualizer import Visualizer from copy import deepcopy from time import sleep import random random.seed(1) vis = Visualizer() grid = life.setup(50, "random", "strict_border") vis.draw_grid(grid) i = 0 grid_old = None grid_old_old = None while True: try: print(f"Step {i}") if grid_old: grid_old_old = deepcopy(grid_old) grid_old = deepcopy(grid) grid = life.make_step(grid) if grid_old and grid_old_old: if life._check_empty(grid) or \ life._check_stable(grid, grid_old, grid_old_old): print("Game ended!") break if i % 1 == 0: vis.draw_grid(grid) i += 1 sleep(0.2)