import copy mov_format={0:'a:0',1:'b:0',2:'c:0',3:'a:1',4:'b:1'} mov_format[5]='c:1' mov_format[6]='a:2' mov_format[7]='b:2' mov_format[8]='c:2' mec=0 ec=0 bc=0 etwo=0 mtwo=0 def CPU_Turn(board,syme,sye): scr=0 mscore=0 count=-1 iboard=[] imoves={} for x in board: for xc in x: count=count+1 if xc=='.': imoves[count]=1 for x in imoves.keys(): iboard=copy.deepcopy(board) if x<3: iboard[0][x]=syme elif x<6: iboard[1][(x-3)]=syme else: iboard[2][(x-6)]=syme imoves[x]=CPU_BTest(iboard,syme,sye,scr) scr=0 ## print imoves.keys() ## print imoves.values() topkey=imoves.keys()[0] for x in imoves.keys(): if imoves[x] >= mscore: mscore=imoves[x] topkey=x ## print topkey ## print mov_format[topkey] return mov_format[topkey] ## def CPU_BTest(iboard,me,e,scr): global mec,ec,bc,etwo,mtwo count=0 while count < 3: line=iboard[count] scr=Test_Line(line,me,e,scr) count=count+1 count=0 while count < 3: line=iboard[0][count]+iboard[1][count]+iboard[2][count] line=list(line) scr=Test_Line(line,me,e,scr) count=count+1 line=iboard[0][0]+iboard[1][1]+iboard[2][2] line=list(line) scr=Test_Line(line,me,e,scr) line=iboard[2][0]+iboard[1][1]+iboard[0][2] line=list(line) scr=Test_Line(line,me,e,scr) return scr ## def Test_Line(line,me,e,scr): global ec,mec,bc,etwo,mtwo ## boardw={0:3,1:1,2:3,3:1,4:2,5:1,6:3,7:1,8:3} ec=mec=bc=etwo=mtwo=0 etwo=mtwo=0 for x in line: if x==e: ec=ec+1 elif x==me: mec=mec+1 else: bc=bc+1 if ec>0: if mec==0: scr=scr-4 if ec>1: etwo=etwo+1 if mec>0: if ec==0: scr=scr+1 if mec>1: mtwo=mtwo+1 if mec==3: scr=scr+1000000 scr=scr-100*etwo scr=scr+5^mtwo return scr ##