Your IP : 216.73.216.213
��Yf'# � @ s~ d Z d d l Z d d l Z Gd d � d � Z d d � Z d d � Z d d
� Z d d � Z e d
k rz e j e � d S)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 Z d Z d Z e d � d d � Z d d � Z d d � Z d d
� Z d d d
� Z d d � Z
d S)� 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 j � \ } } | d | d d | _ | _ | | _ | j j � d | j d d } | j j d d | � | j j | j d d | � xU t d | j � D]A } | j j d | d d � | j j d | | j d d � q� W| j j � d S)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/python35/lib64/python3.5/Tools/demo/life.py�__init__( s
%zLifeBoard.__init__c C sc | d k s6 | j | k s6 | d k s6 | j | k rL t d | | f � � d | j | | f <d S)zSet a cell to the live stater zCoordinates out of range %i,%ir N)r r
�
ValueErrorr )r r �xr r r �set>