def abmin(s, d, a, b): if d == 0 or game.isFinished(s): return [game.value(s), 0] v = float("inf") ns = game.getNext(s) bestMove = 0 for i in ns: tmp = abmax(copy.deepcopy(i), d - 1, a, b) if tmp[0] < v: v = tmp[0] bestMove = i if v <= a: return [v, i] if v < b: b = v return [v, bestMove]
def abmin(gm, d, a, b): if d == 0 or game.isFinished(gm): game.checkSeq(gm) return [game.value(gm), 0] v = float("inf") ns = game.getNext(gm) bestMove = 0 for st in ns: tmp = abmax(st, d - 1, a, b) if tmp[0] < v: v = tmp[0] bestMove = st if v <= a: return [v, st] if v < b: b = v return [v, bestMove]
def abmax(gm, d, a, b): if d == 0 or game.isFinished(gm): # print("returns ", [game.value(gm), gm]) game.checkSeq(gm) return [game.value(gm), gm] v = float("-inf") ns = game.getNext(gm) bestMove = 0 for st in ns: tmp = abmin(st, d - 1, a, b) if tmp[0] > v: v = tmp[0] bestMove = st if v >= b: return [v, st] if v > a: a = v return [v, bestMove]
def abmax(gm, d, a, b): print("now calculate abmax") print("d=", d) print("alpha=", a) print("beta=", b) if d == 0 or game.isFinished(gm): print("returns ", [game.value(gm), gm]) return [game.value(gm), gm] v = float("-inf") ns = game.getNext(gm) print("next moves:", len(ns), " possible moves ") bestMove = 0 for st in ns: tmp = abmin(st, d - 1, a, b) if tmp[0] > v: v = tmp[0] bestMove = st if v >= b: return [v, st] if v > a: a = v return [v, bestMove]
def abmin(gm, d, a, b): #print("now calculate abmin") #print("d=", d) #print("a=", a) #print("b=", b) if d == 0 or game.isFinished(gm): #print("returns ", [game.value(gm), gm]) return [game.value(gm), 0] v = float("inf") ns = game.getNext(gm) #print("next moves:", len(ns), " possible moves ") bestMove = 0 for st in ns: tmp = abmax(st, d - 1, a, b) if tmp[0] < v: v = tmp[0] bestMove = st if v <= a: return [v, st] if v < b: b = v return [v, bestMove]