game.py 867 B

123456789101112131415161718192021222324252627282930
  1. from GameOfLifeLibrary import GameOfLife
  2. import sys
  3. import argparse
  4. parser = argparse.ArgumentParser()
  5. parser.add_argument("--file", help="File to read. Default is stdin", default='stdin')
  6. args = parser.parse_args()
  7. use_prompt = False
  8. if not args.file == 'stdin':
  9. sys.stdin = open(args.file, 'r')
  10. else:
  11. use_prompt = True
  12. sizex, sizey, gens = (int(i) for i in input('Enter width, height and number '
  13. 'of gens splitted by whitespaces: '
  14. if use_prompt else ''
  15. ).split())
  16. a = GameOfLife(sizex, sizey)
  17. print('Enter field (and after that use Ctrl+D to stop input stream): ')
  18. a.parse_field([line[:-1] if line[-1] == '\n' else line for line in sys.stdin.readlines()])
  19. for i in range(gens):
  20. a.iterate()
  21. a.print_field()