def play(self):
        """ Play Conway's Game of Life. """

        # Write the initial configuration to file.

        self.t = 1  # Current time level
        while self.t <= self.T:  # Evolve!
            # print( "At time level %d" % t)

            # Loop over each cell of the grid and apply Conway's rules.
            for i in range(self.N):
                for j in range(self.N):
                    live = self.live_neighbours(i, j)
                    if (self.old_grid[i][j] == 1 and live < 2):
                        self.new_grid[i][j] = 0  # Dead from starvation.
                    elif (self.old_grid[i][j] == 1 and (live == 2 or live == 3)):
                        self.new_grid[i][j] = 1  # Continue living.
                    elif (self.old_grid[i][j] == 1 and live > 3):
                        self.new_grid[i][j] = 0  # Dead from overcrowding.
                    elif (self.old_grid[i][j] == 0 and live == 3):
                        self.new_grid[i][j] = 1  # Alive from reproduction.

            # Output the new configuration.

            # The new configuration becomes the old configuration for the next generation.
            self.old_grid = self.new_grid.copy()
            self.draw_board()
            # Move on to the next time level
            self.t += 1
def play ( self ) : self . t = 1 while self . t <= self . T : for i in range ( self . N ) : for j in range ( self . N ) : live = self . live_neighbours ( i , j ) if ( self . old_grid [ i ] [ j ] == 1 and live < 2 ) : self . new_grid [ i ] [ j ] = 0 elif ( self . old_grid [ i ] [ j ] == 1 and ( live == 2 or live == 3 ) ) : self . new_grid [ i ] [ j ] = 1 elif ( self . old_grid [ i ] [ j ] == 1 and live > 3 ) : self . new_grid [ i ] [ j ] = 0 elif ( self . old_grid [ i ] [ j ] == 0 and live == 3 ) : self . new_grid [ i ] [ j ] = 1 self . old_grid = self . new_grid . copy ( ) self . draw_board ( ) self . t += 1
Play Conway's Game of Life.