³ò úÂiFcsôddkTddkZdZeeƒZdZeeZdZeZ d„Z d„Z d „Z d „Z d „Zd „Zd „Zd„ZeegZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZeƒdS(s1Check to see if the latest move resulted in a winiÿÿÿÿ(t*Nii–ic s~xwtdtƒD]f}ttd|tƒtt|tƒƒitƒtt|tdƒt|ttƒƒitƒqWdS(Nii( tranget BOARDSIZEtitLinetPointtPPSt WINDOWSIZEtdrawtwin( RRRRRRRRR ((s TicTacToe6.pysdrawGrids0cs)tt|tdt|tdƒSdS(scoordinates of center of squareiN(RRtcoltrow(R R RR((s TicTacToe6.pys rectCenterscs!tt|tt|tƒSdS(s'coordinates of top left of inset X or ON(RRR tINSETR (R R RRR ((s TicTacToe6.pys rectUpperLeftscs)tt|dtt|dtƒSdS(s+coordinates of bottom right of inset X or OiN(RRR R R (R R RRR ((s TicTacToe6.pysrectLowerRightscs%tt|dtt|tƒSdS(s(coordinates of top right of inset X or OiN(RRR R R (R R RRR ((s TicTacToe6.pysrectUpperRight"scs%tt|tt|dtƒSdS(s*coordinates of bottom left of inset X or OiN(RRR R R (R R RRR ((s TicTacToe6.pys rectLowerLeft&sc sTtt||ƒt||ƒƒitƒtt||ƒt||ƒƒitƒdS(sDraw an X in the given squareN( Rt rectUpperLeftR R trectLowerRightRR t rectLowerLefttrectUpperRight( R R RR RRR RR((s TicTacToe6.pysdrawX,s(cs/tt||ƒtdtƒitƒddS(sDraw an O in the given squareiN(tCirclet rectCenterR R RR RR (R R RRRR RR ((s TicTacToe6.pysdrawO1scs|tSddS(sFFind out row or colum number that corresponds to this pixel coordinateN(t pixelCoordR(RR((s TicTacToe6.pys boardCoord8scsQg}x@tD]8}g}xtD]}|d g7}q W||g7}q W|SdS(s#Initialize the state of each squareiN(t squareStatet BOARDRANGERtinnertj(RRRRR((s TicTacToe6.pysinitSquareState=scs t||}t||ƒo$t|dƒt|tdƒgSnt||ƒo$td|ƒttd|ƒgSn||jo t |ƒo(tddƒttdtdƒgSn||tdjo t |ƒo(t dtdƒt tddƒgSnt SdS(s1Check to see if the latest move resulted in a winiiN(RR R txotcheckRowR RRtcheckColtcheckMainDiagonaltcheckOtherDiagonalRRtFalse(R R RRRR RRRRRRRR((s TicTacToe6.pys checkWinnerIs$$("(cst|ddd|ƒSdS(Nii(t checkGeneralR R(R RR((s TicTacToe6.pyscheckRowVscstd|dd|ƒSdS(Nii(RR R(R RR((s TicTacToe6.pyscheckColXscstdddd|ƒSddS(Nii(RR(RR((s TicTacToe6.pyscheckMainDiagonalZscstdtddd |ƒSdS(Nii(RRR(RRR((s TicTacToe6.pyscheckOtherDiagonal\sc sJx?tD]7}t|||jotSn||7}||7}qWt SdS(N( RRRR R RRt rowIncrementt colIncrementtTrue( R R RR RRRRRR!((s TicTacToe6.pys checkGeneral_s c"stdƒ}|djo&t|ƒattƒattantdttƒa t ƒa t ƒd} xü| ttjoêt iƒ}t|iƒƒt|iƒƒf\}}t ||d jošt| d||ƒ| dt ||<| d} t||ƒ}|oOtt|ƒ}d|idƒ|idƒ|id dƒ|it ƒPnnqjWti d ƒt i!ƒdS( Ns&Enter board size (Press Enter for 3): tsTicTacToe version 6iiitrediii("t raw_inputtuserSizetevalRRRRRtGraphWinR tinitSquareStateRtdrawGridt turnCounttgetMouset clickPointt boardCoordtgetYtgetXR R tdrawListt checkWinnertwinnertapplyRtwinLinet setOutlinetsetWidthtmoveRttimetsleeptclose("R$R%R&RRRRRR'R R(RR)R*R+R,R-R.R/R R R0R1R2R3RR4R5R6R7RR8R9R:((s TicTacToe6.pysmainhs6      *     (tgraphicsR8RRRRRR tNoneR R)RR RRRtdrawXtdrawOR0R-R(R1RRRRRtmain(R;R8RRRRRR R<R R)RR RRRR=R>R0R-R(R1RRRRRR?((s TicTacToe6.pyss4                   #