ó ¿œ^c@s5dZddlZddlZddlZdZdZdZdZedZeedd edd Z dZ dZ dZ d„Z d„Zd„Zdefd„ƒYZdejfd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZd„Zedkr1eƒejƒndS( 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àiii ii ii?iÿiÌcCstjttƒS(N(trandomtrandintt MINSTICKSt MAXSTICKS(((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyt randomrowscCsy|d|dA|dA}|dkr0t|ƒSxBtdƒD]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   tNimModelcBs5eZd„Zd„Zd„Zd„Zd„ZRS(cCs ||_dS(N(tgame(tselfR((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyt__init__6scCsr|jjtjtjgkr"dStƒtƒtƒg|_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ƒ|jƒrstj|j_|j|_ |jjj ƒnI|jdkr¼d|_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#eZd„Zd„Zd„ZRS(cCs°tjj|dtƒ||_||_||_|j||ƒ\}}|jdƒ|j t dt dƒ|j dƒ|j ƒ|j||ƒ|jdƒ|jƒdS(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|jƒdS(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  tNimViewcBsAeZd„Zdd„Zd„Zd„Zd„Zd„ZRS(cCsú||_|j|_|j|_|jjdƒ|jjtƒ|jjdƒtjdtƒ|_ |j j ƒ|j j dƒi|_ xJt dƒD]<}x3t tƒD]%}t|||ƒ|j ||f s0      $E