# L-15 MCS 507 Mon 25 Sep 2023 : run_game_better_apply.py

"""
Using the same main() function as in run_game_of_life.py,
code of the run_game_better module is called.
"""

from time import perf_counter
import numpy as np
from run_game_better import update

def main():
    """
    Generates a random matrix and
    applies the rules for Conway's
    game of life.
    """
    ratio = 0.2  # ratio of nonzeroes
    dim = 200    # dimension of the matrix
    alive = np.random.rand(dim, dim)
    alive = np.matrix(alive < ratio, np.uint8)
    start_time = perf_counter()
    for i in range(dim):
        alive = update(alive)
    stop_time = perf_counter()
    elapsed = stop_time - start_time
    print('elapsed time', elapsed, 'seconds')

main()
