123456789101112131415161718192021222324252627282930 |
- from GameOfLifeLibrary import GameOfLife
- import sys
- import argparse
- parser = argparse.ArgumentParser()
- parser.add_argument("--file", help="File to read. Default is stdin", default='stdin')
- args = parser.parse_args()
- use_prompt = False
- if not args.file == 'stdin':
- sys.stdin = open(args.file, 'r')
- else:
- use_prompt = True
- sizex, sizey, gens = (int(i) for i in input('Enter width, height and number '
- 'of gens splitted by whitespaces: '
- if use_prompt else ''
- ).split())
- a = GameOfLife(sizex, sizey)
- print('Enter field (and after that use Ctrl+D to stop input stream): ')
- a.parse_field([line[:-1] if line[-1] == '\n' else line for line in sys.stdin.readlines()])
- for i in range(gens):
- a.iterate()
- a.print_field()
|