Your IP : 18.191.240.117


Current Path : /lib64/python2.7/Demo/turtle/
Upload File :
Current File : //lib64/python2.7/Demo/turtle/tdemo_nim.pyc

�
V
�Qc@s^dZddlZddlZddlZdZdZdZdZedZeedd	edd
Z	dZ
dZd Zd�Z
d�Zd�Zdefd��YZdejfd��YZdefd��YZdefd��YZdefd��YZej�Zejd�ejee�d�ZedkrZe�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iiii?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.pytcomputerzug!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(
RRRtnotify_moveRt	game_overRRRRtnotify_overRR(Rtrowtcolt	maxspalte((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyRBs

	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__RRRR R(((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR5s
					tStickcBs#eZd�Zd�Zd�ZRS(cCs�tjj|dt�||_||_||_|j||�\}}|jd�|j	t
dtd�|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(Niiii(tdivmodR2R1tSCREENWIDTHt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	jd�i|_xJt
d�D]<}x3t
t�D]%}t|||�|j||f<q�Wq�W|jd�|jjt�dS(Ni�i�R(iis... a moment please ...(i�i�i�(Rtscreentmodelt	colormodettracerR-tbgcolorR+R,twriterR4R3RRRR'tdisplayR(RRR"R#((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyRus	
	'
cCs�|jjt�|jj�|dk	rt|jjdtdd�|jjd�|jj	|dddd�n|jjdtdd�|jjd�|jj	|dddd�|jjt
�dS(Niii0tredtaligntcentertfonttCourieritbolditblacki(RMiRN(RMiRN(RBRER-RGtclearRR5R<tpencolortwriteR(Rtmsg1tmsg2((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyRH�s
cCs�|jjt�xOtd�D]A}x8t|jj|�D] }|j||fjt�q:WqWxRtd�D]D}x;t|jj|t�D] }|j||fjd�q�WqoW|j	d�|jjt
�dS(NiR*s*Your turn! Click leftmost stick to remove.(RBRER-RRCRR6tSCOLORRRHR(RR"R#((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR�s" "
cCs�|dkrIt}x�t||�D] }|j||fj|�q"Wn�|jd�tjd�|jd�t}xIt|d|dd�D]-}tjd�|j||fj|�q�W|jd�dS(	Nis ... thinking ...         g�?s ... thinking ... aaah ...ii����g�������?s*Your turn! Click leftmost stick to remove.(tHCOLORRRR6RHttimetsleeptCOLOR(RR"R#R$RtfarbeR
((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR�s!


!
cCs8|jjjdkrd}nd}|jd|�dS(NisCongrats. You're the winner!!!s"Sorry, the computer is the winner.s2To play again press space bar. To leave press ESC.(RRCRRH(RRT((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR!�s	cCs)|jjtjkr%|jj�ndS(N(RRRRRBRP(R((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyRP�sN(	R%R&RRRHRRR!RP(((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyRAts	
			t
NimControllercBseZd�Zd�ZRS(cCs�||_|jj|_t|_x'|jj�D]}|j|j�q1W|jjj	|jj
jd�|jjj	|jjjd�|jjj
d�|jjj�dS(NtspacetEscapesPress space bar to start game(RRRR-tBUSYtvaluestonclickR@RBtonkeyRCRRPRHtlisten(RRtstick((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR�s		cCs9|jr
dSt|_|jjj||�t|_dS(N(R^RRRCRR-(RR"R#((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR�s
		(R%R&RR(((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR[�s	RcBs#eZdZdZdZd�ZRS(iiicCsFtj|_||_t|�|_t|�|_t|�|_	dS(N(
RRRRBRRCRARR[R?(RRB((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR�s
	(R%R&RRRR(((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyR�ststandardcCstt�}dS(Ns
EVENTLOOP!(Rt
mainscreen(tnim((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pytmain�st__main__(i?i?i(i�i�i�(i�i�i�(t__doc__R+RRWR;R<RRR1R2RURVRYRRRtobjectRR,R'RAR[RtScreenRetmodeRRgR%tmainloop(((s-/usr/lib64/python2.7/Demo/turtle/tdemo_nim.pyt<module>
s6
		
	
$D