� ��^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 r1e � 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&