def MidMinMax(board,depth,a,b):#black turn if depth==0: return [static(board),board,board] flag = checkStep(board) if flag==2 or flag==3: return EndMinMax(board,depth,a,b) inv = game.getInverse(board) positions = game.generateMove(inv) if depth==0 or not positions: return [static(board),board,board] else: v = [float('inf'),None,None] for pos in positions: v = min(v,MidMaxMin(pos,depth-1,a,b)[:-1]+[pos],key = lambda x:x[0]) if(v[0]<=a): return v else: b = min(v[0],b) return v
def static(board): #flag: 0 white 1 black global estTime numW, numB = 0, 0 for b in board: if b == 'W': numW += 1 elif b == 'B': numB += 1 estTime += 1 if numB <= 2: return 10000 if numW <= 2: return -10000 inv = game.getInverse(board) if numB == 3: moves = len(game.generateHopping(inv)) else: moves = len(game.generateMove(inv)) #print(1000*(numW-numB)-moves,numW,numB,moves) return 1000 * (numW - numB) - moves
def MidMaxMin(board,depth,a,b):#white turn game.change(board) if depth==0: return [static(board),board,board] flag = checkStep(board) if flag==1 or flag==3: return EndMaxMin(board,depth,a,b) positions = game.generateMove(board) if depth==0 or not positions: return [static(board),board,board] else: v = [-float('inf'),None,None] for pos in positions: v = max(v,MidMinMax(pos,depth-1,a,b)[:-1]+[pos],key = lambda x:x[0]) if(v[0]>=b): return v else: a = max(v[0],a) return v