???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................ó
¿œ^c           @   s5  d  Z  d d l Z d d l Z d d l Z d Z d Z d Z d Z e d Z e e d d	 e d d
 Z	 d Z
 d Z d Z d „  Z d „  Z d „  Z d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z e d k r1e ƒ  e j ƒ  n  d S(    s¿         turtle-example-suite:

            tdemo_nim.py

Play nim against the computer. The player
who takes the last stick is the winner.

Implements the model-view-controller
design pattern.
iÿÿÿÿNi€  ià  i   i   i   i   i   i   i?   iÿ   iÌ   c           C   s   t  j t t ƒ S(   N(   t   randomt   randintt	   MINSTICKSt	   MAXSTICKS(    (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyt	   randomrow   s    c         C   sy   |  d |  d A|  d A} | d k r0 t  |  ƒ SxB t d ƒ D]4 } |  | | A} | |  | k r= | | f } | Sq= Wd  S(   Ni    i   i   i   (   t
   randommovet   range(   t   statet   xoredt   zt   st   move(    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyt   computerzug!   s    
c         C   so   t  |  ƒ } x6 t rD t j d d ƒ } |  | | d k k r Pq q Wt j | d k |  | d ƒ } | | f S(   Ni    i   i   (   t   maxt   TrueR    R   (   R   t   mR	   t   rand(    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   +   s    	 t   NimModelc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   t   game(   t   selfR   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyt   __init__6   s    c         C   sr   |  j  j t j t j g k r" d  St ƒ  t ƒ  t ƒ  g |  _ d |  _ d  |  _	 |  j  j
 j ƒ  t j |  j  _ d  S(   Ni    (   R   R   t   Nimt   CREATEDt   OVERR   t   stickst   playert   Nonet   winnert   viewt   setupt   RUNNING(   R   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   9   s    		c         C   sÀ   |  j  | } | |  j  | <|  j j j | | | |  j ƒ |  j ƒ  rs t j |  j _ |  j |  _	 |  j j j
 ƒ  nI |  j d k r¼ d |  _ t |  j  ƒ \ } } |  j | | ƒ d |  _ n  d  S(   Ni    i   (   R   R   R   t   notify_moveR   t	   game_overR   R   R   R   t   notify_overR   R   (   R   t   rowt   colt	   maxspalte(    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   B   s    	c         C   s   |  j  d d d g k S(   Ni    (   R   (   R   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR    P   s    c         C   s+   |  j  | | k r d  S|  j | | ƒ d  S(   N(   R   R   (   R   R"   R#   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   S   s    (   t   __name__t
   __module__R   R   R   R    R   (    (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   5   s
   					t   Stickc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s°   t  j j |  d t ƒ| |  _ | |  _ | |  _ |  j | | ƒ \ } } |  j d ƒ |  j	 t
 d t d ƒ |  j d ƒ |  j ƒ  |  j | | ƒ |  j d ƒ |  j ƒ  d  S(   Nt   visiblet   squareg      $@g      4@i    t   white(   t   turtlet   TurtleR   t   FalseR"   R#   R   t   coordst   shapet	   shapesizet   HUNITt   WUNITt   speedt   put   gotot   colort
   showturtle(   R   R"   R#   R   t   xt   y(    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   Z   s    			
c         C   sk   t  | d ƒ \ } } d d | d | t } d d | t } | t d t d t d | t d f S(   Ni   i   i   i   (   t   divmodR2   R1   t   SCREENWIDTHt   SCREENHEIGHT(   R   R"   R#   t   packett	   remainderR8   R9   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR.   h   s    c         C   s9   |  j  j t j k r d  S|  j  j j |  j |  j ƒ d  S(   N(   R   R   R   R   t
   controllerR   R"   R#   (   R   R8   R9   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyt   makemoven   s    (   R%   R&   R   R.   R@   (    (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR'   Y   s   		t   NimViewc           B   sA   e  Z d  „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sú   | |  _  | j |  _ | j |  _ |  j j d ƒ |  j j t ƒ |  j j d ƒ t j d t ƒ |  _	 |  j	 j
 ƒ  |  j	 j d ƒ i  |  _ xJ t d ƒ D]< } x3 t t ƒ D]% } t | | | ƒ |  j | | f <q¬ Wq™ W|  j d ƒ |  j j t ƒ d  S(   Niÿ   ið   R(   i    i   s   ... a moment please ...(   ið   ið   iÿ   (   R   t   screent   modelt	   colormodet   tracerR-   t   bgcolorR+   R,   t   writerR4   R3   R   R   R   R'   t   displayR   (   R   R   R"   R#   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   u   s    		'c         C   sÐ   |  j  j t ƒ |  j j ƒ  | d  k	 rt |  j j d t d d ƒ |  j j d ƒ |  j j	 | d d d d ƒn  |  j j d t d d ƒ |  j j d ƒ |  j j	 | d d d d ƒ|  j  j t
 ƒ d  S(   Ni    i   i0   t   redt   alignt   centert   fontt   Courieri   t   boldi   t   blacki   (   RM   i   RN   (   RM   i   RN   (   RB   RE   R-   RG   t   clearR   R5   R<   t   pencolort   writeR   (   R   t   msg1t   msg2(    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyRH   †   s    c         C   sØ   |  j  j t ƒ xO t d ƒ D]A } x8 t |  j j | ƒ D]  } |  j | | f j t ƒ q: Wq WxR t d ƒ D]D } x; t |  j j | t ƒ D]  } |  j | | f j d ƒ q Wqo W|  j	 d ƒ |  j  j t
 ƒ d  S(   Ni   R*   s*   Your turn! Click leftmost stick to remove.(   RB   RE   R-   R   RC   R   R6   t   SCOLORR   RH   R   (   R   R"   R#   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   “   s    " "c         C   sÓ   | d k rI t  } xº t | | ƒ D]  } |  j | | f j | ƒ q" Wn† |  j d ƒ t j d ƒ |  j d ƒ t } xI t | d | d d ƒ D]- } t j d ƒ |  j | | f j | ƒ q‘ W|  j d ƒ d  S(	   Ni    s    ... thinking ...         g      à?s    ... thinking ... aaah ...i   iÿÿÿÿgš™™™™™É?s*   Your turn! Click leftmost stick to remove.(   t   HCOLORR   R   R6   RH   t   timet   sleept   COLOR(   R   R"   R#   R$   R   t   farbeR
   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   ž   s    !!c         C   s8   |  j  j j d k r d } n d } |  j d | ƒ d  S(   Ni    s   Congrats. You're the winner!!!s"   Sorry, the computer is the winner.s2   To play again press space bar. To leave press ESC.(   R   RC   R   RH   (   R   RT   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR!   ­   s    	c         C   s)   |  j  j t j k r% |  j j ƒ  n  d  S(   N(   R   R   R   R   RB   RP   (   R   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyRP   ´   s    N(	   R%   R&   R   R   RH   R   R   R!   RP   (    (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyRA   t   s   				t   NimControllerc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s°   | |  _  | j j |  _ t |  _ x' |  j j ƒ  D] } | j | j ƒ q1 W|  j  j j	 |  j  j
 j d ƒ |  j  j j	 |  j  j j d ƒ |  j  j j d ƒ |  j  j j ƒ  d  S(   Nt   spacet   Escapes   Press space bar to start game(   R   R   R   R-   t   BUSYt   valuest   onclickR@   RB   t   onkeyRC   R   RP   RH   t   listen(   R   R   t   stick(    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   »   s    		c         C   s9   |  j  r d  St |  _  |  j j j | | ƒ t |  _  d  S(   N(   R^   R   R   RC   R   R-   (   R   R"   R#   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   Æ   s
    		(   R%   R&   R   R   (    (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR[   ¹   s   	R   c           B   s#   e  Z d  Z d Z d Z d „  Z RS(   i    i   i   c         C   sF   t  j |  _ | |  _ t |  ƒ |  _ t |  ƒ |  _ t |  ƒ |  _	 d  S(   N(
   R   R   R   RB   R   RC   RA   R   R[   R?   (   R   RB   (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   Ñ   s
    	(   R%   R&   R   R   R   R   (    (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR   Í   s   c          C   s9   t  j ƒ  }  |  j d ƒ |  j t t ƒ t |  ƒ } d S(   Nt   standards
   EVENTLOOP!(   R+   t   Screent   modeR   R;   R<   R   (   t
   mainscreent   nim(    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyt   mainÙ   s
    t   __main__(   i?   i?   i   (   iÿ   iÌ   iÌ   (   iÌ   iÌ   iÿ   (   t   __doc__R+   R    RW   R;   R<   R   R   R1   R2   RU   RV   RY   R   R   R   t   objectR   R,   R'   RA   R[   R   Ri   R%   t   mainloop(    (    (    s-   /usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyt   <module>
   s0   
		
	
$E	