Your IP : 216.73.216.213
�
��f'# c @ 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 r} e j e � n d S( u�
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.
i Nc B sn | Ee 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( u LifeBoardu� 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
u *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( u� Create a new LifeBoard instance.
scr -- curses screen object to use for display
char -- character used to render live cells (default: '*')
i i u +u -i u |N(
u stateu scru getmaxyxu Xu Yu charu clearu addstru rangeu refresh( u selfu scru charu Yu Xu border_lineu y( ( u4 /opt/alt/python33/lib64/python3.3/Tools/demo/life.pyu __init__( s
%u LifeBoard.__init__c C sf | d k s6 | j | k s6 | d k s6 | j | k rO t d | | f � � n d | j | | f <d S( u Set a cell to the live statei u Coordinates out of range %i,%ii N( u Xu Yu
ValueErroru state( u selfu yu x( ( u4 /opt/alt/python33/lib64/python3.3/Tools/demo/life.pyu set>