Your IP : 216.73.216.213
B
� f'# � @ sX d Z ddlZddlZG dd� d�Zdd� Zdd� Zd d
� Zdd� Zed
krTe� e� dS )a�
A curses-based version of Conway's Game of Life.
An empty board will be displayed, and the following commands are available:
E : Erase the board
R : Fill the board randomly
S : Step for a single generation
C : Update continuously until a key is struck
Q : Quit
Cursor keys : Move the cursor around the board
Space or Enter : Toggle the contents of the cursor's position
Contributed by Andrew Kuchling, Mouse support and color by Dafydd Crosby.
� Nc @ sJ e Zd ZdZed�fdd�Zdd� Zdd� Zd d
� Zddd
�Z dd� Z
dS )� LifeBoarda� Encapsulates a Life board
Attributes:
X,Y : horizontal and vertical size of the board
state : dictionary mapping (x,y) to 0 or 1
Methods:
display(update_board) -- If update_board is true, compute the
next generation. Then display the state
of the board and refresh the screen.
erase() -- clear the entire board
make_random() -- fill the board randomly
set(y,x) -- set the given cell to Live; doesn't refresh the screen
toggle(y,x) -- change the given cell from live to dead, or vice
versa, and refresh the screen display
�*c C s� i | _ || _| j�� \}}|d |d d | _| _|| _| j�� d| jd d }| j�dd|� | j�| jd d|� xBtd| j�D ]2}| j�d| dd� | j�d| | jd d� q�W | j� � dS )z�Create a new LifeBoard instance.
scr -- curses screen object to use for display
char -- character used to render live cells (default: '*')
� � �+�-r �|N)
�state�scr�getmaxyx�X�Y�char�clear�addstr�range�refresh)�selfr
r r
r Zborder_line�y� r �4/opt/alt/python37/lib64/python3.7/Tools/demo/life.py�__init__( s
zLifeBoard.__init__c C sF |dk s$| j |ks$|dk s$| j|kr4td||f ��d| j||f<