[DSTG] Zadatak 4.
def minimax(igrajer, ploca, depth, evaluate):
def value(ploca):
return -minimax(protivnik(igrajer), ploca, depth-1, evaluate)[0]
if depth == 0:
return evaluate(igrajer, ploca), None
moves = legalan_potez(igrajer, ploca)
if not moves:
if not bilokoji_lPotez(protivnik(igrajer), ploca):
return zavrsni_rezultat(igrajer, ploca), None
return value(ploca), None
return max((value(napravi_potez(m, igrajer, list(ploca))), m) for m in moves)
MAX_VALUE = sum(map(abs, TEZINE_PLOCE))
MIN_VALUE = -MAX_VALUE
def zavrsni_rezultat(igrajer, ploca):
diff = rezultat(igrajer, ploca)
if diff < 0:
return MIN_VALUE
elif diff > 0:
return MAX_VALUE
return diff
def minimax_searcher(depth, evaluate):
def strategy(igrajer, ploca):
return minimax(igrajer, ploca, depth, evaluate)[1]
return strategy