code: def main():
      
      def die((x, y)):
          """Pretend any out-of-bounds cell is dead."""
          if 0 <= x < width and 0 <= y < height:
              return x, y
  
      LOAD_FACTOR = 9  # Smaller means more crowded.
      NUDGING_LOAD_FACTOR = LOAD_FACTOR * 3  # Smaller means a bigger nudge.
  
      term = Terminal()
      width = term.width
      height = term.height
      board = random_board(width - 1, height - 1, LOAD_FACTOR)
      detector = BoredomDetector()
      cells = cell_strings(term)
  
      with nested(term.fullscreen(), term.hidden_cursor()):
          try:
              while True:
                  frame_end = time() + 0.05
                  board = next_board(board, die)
                  draw(board, term, cells)
  
                  # If the pattern is stuck in a loop, give it a nudge:
                  if detector.is_bored_of(board):
                      board.update(random_board(width - 1,
                                                height - 1,
                                                NUDGING_LOAD_FACTOR))
  
                  stdout.flush()
                  sleep_until(frame_end)
                  clear(board, term, height)
          except KeyboardInterrupt:
              pass
docs: Play Conway's Game of Life on the terminal.