AlkantarClanX12

Your IP : 3.16.69.243


Current Path : /usr/lib64/python3.8/turtledemo/__pycache__/
Upload File :
Current File : //usr/lib64/python3.8/turtledemo/__pycache__/nim.cpython-38.opt-2.pyc

U

e5dq�@s�ddlZddlZddlZdZdZdZdZedZeeddedd	Zd
Z	dZ
dZd
d�Zdd�Z
dd�ZGdd�de�ZGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�Zdd�Zedkr�e�e��dS) �Ni�i�������)�?rr)���r
)r
r
r	cCst�tt�S�N)�random�randint�	MINSTICKS�	MAXSTICKS�rr�&/usr/lib64/python3.8/turtledemo/nim.py�	randomrowsrcCsb|d|dA|dA}|dkr(t|�Std�D],}|||A}|||kr0||f}|Sq0dS)Nr�r�)�
randommove�range)�stateZxored�z�s�moverrr�computerzug!srcCsHt|�}t�dd�}|||dkkrq(qt�|dk||d�}||fS)Nrrr)�maxrr
)r�mrZrandrrrr+src@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�NimModelcCs
||_dSr)�game)�selfrrrr�__init__6szNimModel.__init__cCsP|jjtjtjfkrdSt�t�t�g|_d|_d|_|jj	�
�tj|j_dS�Nr)rr�Nim�CREATED�OVERr�sticks�player�winner�view�setup�RUNNING�r rrrr*9szNimModel.setupcCs�|j|}||j|<|jj�||||j�|��rRtj|j_|j|_	|jj�
�n0|jdkr�d|_t|j�\}}|�||�d|_dS)Nrr)
r&rr)�notify_mover'�	game_overr#r%rr(�notify_overrr)r �row�col�	maxspalterrrrBs



z
NimModel.movecCs|jdddgkSr")r&r,rrrr.PszNimModel.game_overcCs"|j||krdS|�||�dSr)r&r�r r0r1rrrr-SszNimModel.notify_moveN)�__name__�
__module__�__qualname__r!r*rr.r-rrrrr5s
	rc@s$eZdZdd�Zdd�Zdd�ZdS)�StickcCs�tjj|dd�||_||_||_|�||�\}}|�d�|�t	dt
d�|�d�|��|�
||�|�d�|��dS)NF�ZvisibleZsquareg$@g4@r�white)�turtle�Turtler!r0r1r�coords�shapeZ	shapesize�HUNIT�WUNIT�speed�pu�goto�colorZ
showturtle)r r0r1r�x�yrrrr!Zs


zStick.__init__cCs^t|d�\}}dd|d|t}dd|t}|tdtdtd|tdfS)Nrrrr)�divmodr?r>�SCREENWIDTH�SCREENHEIGHT)r r0r1ZpacketZ	remainderrDrErrrr<hszStick.coordscCs*|jjtjkrdS|jj�|j|j�dSr)rrr#r+�
controllerr-r0r1)r rDrErrr�makemovenszStick.makemoveN)r4r5r6r!r<rJrrrrr7Ysr7c@s>eZdZdd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)�NimViewcCs�||_|j|_|j|_|j�d�|j�d�|j�d�tjdd�|_|j�	�|j�
d�i|_td�D](}tt
�D]}t|||�|j||f<qxql|�d�|j�d�dS)	Nr	F)��rLr	r8rrz... a moment please ...T)r�screen�modelZ	colormode�tracerZbgcolorr:r;�writerrAr@r&rrr7�display)r rr0r1rrrr!us

zNimView.__init__NcCs�|j�d�|j��|dk	rT|j�dtdd�|j�d�|jj|ddd�|j�dtdd	�|j�d
�|jj|ddd�|j�d�dS)
NFrr�0Zred�center)�Courier��bold)ZalignZfont�Zblack)rT�rVT)rMrOrP�clearrBrHZpencolor�write)r Zmsg1�msg2rrrrQ�s
zNimView.displaycCs�|j�d�td�D].}t|jj|�D]}|j||f�t�q(qtd�D]0}t|jj|t�D]}|j||f�d�qbqL|�d�|j�d�dS)NFrr9�*Your turn! Click leftmost stick to remove.T)	rMrOrrNr&rC�SCOLORrrQr3rrrr*�s
z
NimView.setupcCs�|dkr2t}t||�D]}|j||f�|�qnd|�d�t�d�|�d�t}t|d|dd�D]"}t�d�|j||f�|�qh|�d�dS)	Nrz ... thinking ...         g�?z ... thinking ... aaah ...r���g�������?r\)�HCOLORrr&rCrQ�time�sleep�COLOR)r r0r1r2r'Zfarberrrrr-�s



zNimView.notify_movecCs(|jjjdkrd}nd}|�d|�dS)NrzCongrats. You're the winner!!!z"Sorry, the computer is the winner.z2To play again press space bar. To leave press ESC.)rrNr(rQ)r r[rrrr/�szNimView.notify_overcCs|jjtjkr|j��dSr)rrr#r%rMrYr,rrrrY�sz
NimView.clear)N)	r4r5r6r!rQr*r-r/rYrrrrrKts
rKc@seZdZdd�Zdd�ZdS)�
NimControllercCs|||_|jj|_d|_|j��D]}|�|j�q |jj�|jj	j
d�|jj�|jjjd�|jj�d�|jj�
�dS)NFZspaceZEscapezPress space bar to start game)rr)r&�BUSY�valuesZonclickrJrMZonkeyrNr*rYrQZlisten)r rZstickrrrr!�s
zNimController.__init__cCs*|jr
dSd|_|jj�||�d|_dS)NTF)rdrrNr-r3rrrr-�s
zNimController.notify_moveN)r4r5r6r!r-rrrrrc�srcc@s eZdZdZdZdZdd�ZdS)r#rrrcCs0tj|_||_t|�|_t|�|_t|�|_	dSr)
r#r$rrMrrNrKr)rcrI)r rMrrrr!�s


zNim.__init__N)r4r5r6r$r+r%r!rrrrr#�sr#cCs*t��}|�d�|�tt�t|�}dS)NZstandardZ	EVENTLOOP)r:ZScreen�moder*rGrHr#)Z
mainscreenZnimrrr�main�s

rg�__main__)r:rr`rGrHrrr>r?r]r_rbrrr�objectrr;r7rKrcr#rgr4Zmainlooprrrr�<module>
s.

$D