def EndMaxMin(board,depth,a,b):#white turn score = static(board) if abs(score)==10000: return [score,board,board] positions = game.generateHopping(board) if not positions: return [-10000,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
def EndMinMax(board,depth,a,b):#black turn score = static(board) if abs(score)==10000: return [score,board,board] inv = game.getInverse(board) positions = game.generateHopping(inv) if not positions: return [10000,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