³ò ÀiFcs¾ddkTddkZdZeeƒZdZeeZdZeZ d„Z d„Z d „Z d „Z d „Zd „Zd „Zd„ZeegZd„Zd„Zd„ZeƒdS(s#Initialize the state of each squareiÿÿÿÿ(t*Nii2ic s~xwtdtƒD]f}ttd|tƒtt|tƒƒitƒtt|tdƒt|ttƒƒitƒqWdS(Nii( tranget BOARDSIZEtitLinetPointtPPSt WINDOWSIZEtdrawtwin( RRRRRRRRR ((s TicTacToe5.pysdrawGrids0cs)tt|tdt|tdƒSdS(scoordinates of center of squareiN(RRtcoltrow(R R RR((s TicTacToe5.pys rectCenterscs!tt|tt|tƒSdS(s'coordinates of top left of inset X or ON(RRR tINSETR (R R RRR ((s TicTacToe5.pys rectUpperLeftscs)tt|dtt|dtƒSdS(s+coordinates of bottom right of inset X or OiN(RRR R R (R R RRR ((s TicTacToe5.pysrectLowerRight scs%tt|dtt|tƒSdS(s(coordinates of top right of inset X or OiN(RRR R R (R R RRR ((s TicTacToe5.pysrectUpperRight$scs%tt|tt|dtƒSdS(s*coordinates of bottom left of inset X or OiN(RRR R R (R R RRR ((s TicTacToe5.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 TicTacToe5.pysdrawX.s(cs/tt||ƒtdtƒitƒddS(sDraw an O in the given squareiN(tCirclet rectCenterR R RR RR (R R RRRR RR ((s TicTacToe5.pysdrawO3scs|tSddS(sFFind out row or colum number that corresponds to this pixel coordinateN(t pixelCoordR(RR((s TicTacToe5.pys boardCoord:scsQg}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 TicTacToe5.pysinitSquareState?sc stdƒ}|djo&t|ƒattƒattantdttƒa t ƒa t ƒd} x—| ttjo…t iƒ}t|iƒƒt|iƒƒf\}}t ||d jo5t| d||ƒ| dt ||<| d} nqjWtidƒt iƒdS(Ns&Enter board size (Press Enter for 3): tsTicTacToe version 5iiii(t raw_inputtuserSizetevalRRRRRtGraphWinR tinitSquareStateRtdrawGridt turnCounttgetMouset clickPointt boardCoordtgetYtgetXR R tdrawListttimetsleeptclose(RRRRRRRRRR RRRRR R!R"R#R$R R R%R&R'R(((s TicTacToe5.pysmainJs&      * (tgraphicsR&RRRRRR tNoneR RRR RRRtdrawXtdrawOR%R"Rtmain(R)R&RRRRRR R*R RRR RRRR+R,R%R"RR-((s TicTacToe5.pyss(