def main(): # Set the size of the grid. GRID_WIDTH, GRID_HEIGHT = None, None while not GRID_WIDTH and not GRID_HEIGHT: try: GRID_WIDTH, GRID_HEIGHT = [ int(x) for x in input("Enter width and height of the grid: ").split() ] except: print("Something went wrong - make sure you entered\ two positive numbers") # Indicate the number of generations. NUM_GENS = None while not NUM_GENS: try: NUM_GENS = int(input("Enter the number of generations: ")) except: print("Something went wrong - make sure you entered\ one positive number") # Constructs the game grid and configure it. grid = LifeGrid(GRID_WIDTH, GRID_HEIGHT) grid.configure(INIT_CONFIG, list()) # Plays the game. draw(grid) for i in range(NUM_GENS): evolve(grid) draw(grid)
def main(): GRID_WIDTH = int(input("Input width: ")) GRID_HEIGHT = int(input("Input height: ")) NUM_GENS = int(input("Input number of generations: ")) # Constructs the game grid and configure it. grid = LifeGrid(GRID_WIDTH, GRID_HEIGHT) grid.configure(INIT_CONFIG) # Plays the game. draw(grid) for i in range(NUM_GENS): evolve(grid) draw(grid)
def main(): ''' Constructs the game grid and configure it. ''' grid_width = int(input("Enter the width:")) grid_height = int(input("Enter the height:")) num_gens = int(input("Enter the number of generations")) grid = LifeGrid(grid_width, grid_height) try: grid.configure(INIT_CONFIG) # Plays the game. print(draw(grid)) # print("neighbour:",grid.num_live_neighbors(0, 0)) # print("neighbours:",grid.num_live_neighbors(1, 1)) for i in range(num_gens): evolve(grid) time.sleep(1) print(draw(grid)) except IndexError: print( "Please change INIT_CONFIG in correspondance to the chosen width and height" )
def main(): init_config = [] m = 1 n = 4 # Constructs the game grid and configure it. grid_widz = int(input("Enter width: ")) grid_height = int(input("Enter height: ")) num_gens = int(input("Enter number of gens: ")) i = input( "Enter list of coords in tuples (ex: [(1, 1), (1, 2), (2, 2), (3, 2)]: " )[1:-1] while n < len(i): t = (int(i[m]), int(i[n])) init_config.append(t) m += 8 n += 8 grid = LifeGrid(grid_widz, grid_height) grid.configure(init_config) # Plays the game. draw(grid) for i in range(num_gens): evolve(grid) draw(grid)