V Qc@s^dZddlZddlZddlZdZdZdZdZedZeedd edd Z dZ dZ d Z dZ dZdZdefdYZdejfdYZdefdYZdefdYZdefdYZejZejdejeedZedkrZeejndS(!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. iNiiiii ii ii?iicCstjttS(N(trandomtrandintt MINSTICKSt MAXSTICKS(((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyt randomrowscCsy|d|dA|dA}|dkr0t|SxBtdD]4}|||A}|||kr=||f}|Sq=WdS(Niiii(t randommovetrange(tstatetxoredtztstmove((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyt computerzug!s   cCsot|}x6trDtjdd}|||dkkrPqqWtj|dk||d}||fS(Niii(tmaxtTrueRR(RtmR trand((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR+s   tNimModelcBs5eZdZdZdZdZdZRS(cCs ||_dS(N(tgame(tselfR((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyt__init__6scCsr|jjtjtjgkr"dStttg|_d|_d|_ |jj j tj |j_dS(Ni( RRtNimtCREATEDtOVERRtstickstplayertNonetwinnertviewtsetuptRUNNING(R((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR9s  cCs|j|}||j|<|jjj||||j|jrstj|j_|j|_ |jjj nI|jdkrd|_t |j\}}|j ||d|_ndS(Nii( RRRt notify_moveRt game_overRRRRt notify_overR R (Rtrowtcolt maxspalte((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR Bs     cCs|jdddgkS(Ni(R(R((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR PscCs+|j||krdS|j||dS(N(RR (RR"R#((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyRSs(t__name__t __module__RRR R R(((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR5s    tStickcBs#eZdZdZdZRS(cCstjj|dt||_||_||_|j||\}}|jd|j t dt d|j d|j |j|||jd|jdS(Ntvisibletsquareg$@g4@itwhite(tturtletTurtleRtFalseR"R#Rtcoordstshapet shapesizetHUNITtWUNITtspeedtputgototcolort showturtle(RR"R#Rtxty((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyRZs       cCskt|d\}}dd|d|t}dd|t}|tdtdtd|tdfS(Niii i(tdivmodR2R1t SCREENWIDTHt SCREENHEIGHT(RR"R#tpackett remainderR8R9((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR.hscCs9|jjtjkrdS|jjj|j|jdS(N(RRRRt controllerRR"R#(RR8R9((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pytmakemovens(R%R&RR.R@(((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR'Ys  tNimViewcBsAeZdZddZdZdZdZdZRS(cCs||_|j|_|j|_|jjd|jjt|jjdtjdt|_ |j j |j j di|_ xJt dD]<}x3t tD]%}t||||j ||f s6      $D