def main(): ''' Run 50 generations of a random 2-dimensional Game of Life ''' s = '''........................O ......................O.O ............OO......OO............OO ...........O...O....OO............OO OO........O.....O...OO OO........O...O.OO....O.O ..........O.....O.......O ...........O...O ............OO''' t = s.split() c = life2.make_cells(50, 50, False) row = 3 for cell_row in t: col = 3 for cell in cell_row: if cell == 'O': c[row][col] = True col += 1 row += 1 for i in range(0, 1000): stddraw.show(10) life2.evolve(c) a2.draw_cells(c) pygame.display.quit() pygame.quit() sys.exit()
def main(): ''' Draw 50 generations of a glider in a 2-dimensional Game of Life. ''' n = 20 cells = life2.make_cells(n, n, False) life2.glider(cells, 3, 3) a2.draw_cells(cells) for i in range(0, 50): stddraw.show(200) life2.evolve(cells) a2.draw_cells(cells) pygame.display.quit() pygame.quit() sys.exit()
def main(): ''' Run 50 generations of a random 2-dimensional Game of Life ''' n = 50 cells = life2.make_cells(n, n, True) for row in range(0, n): for col in range(0, n): if random.randint(0, 1) == 0: cells[row][col] = False a2.draw_cells(cells) for i in range(0, n): stddraw.show(500) life2.evolve(cells) a2.draw_cells(cells) pygame.display.quit() pygame.quit() sys.exit()
import life2 c = life2.make_cells(3, 4, False) c[0][0] = True c[1][1] = True c[2][2] = True life2.print_cells(c)
import life2 c = life2.make_cells(7, 7, False) life2.glider(c, 0, 0) print('cells') life2.print_cells(c) life2.evolve(c) print('evolve') life2.print_cells(c)
import life2 c = life2.make_cells(5, 5, False) c[0][0] = True c[1][1] = True c[2][2] = True c[3][3] = True c[4][4] = True print('cells') life2.print_cells(c) print('neighborhood(c, 0, 0)') n = life2.neighborhood(c, 0, 0) life2.print_cells(n) print('neighborhood(c, 0, 2)') n = life2.neighborhood(c, 0, 2) life2.print_cells(n) print('neighborhood(c, 2, 2)') n = life2.neighborhood(c, 2, 2) life2.print_cells(n) print('neighborhood(c, 3, 4)') n = life2.neighborhood(c, 3, 4) life2.print_cells(n)