Created
January 30, 2014 16:17
-
-
Save jsam/8712248 to your computer and use it in GitHub Desktop.
[DSTG] Zadatak 5.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def alphabeta(igrajer, ploca, alpha, beta, depth, evaluate): | |
if depth == 0: | |
return evaluate(igrajer, ploca), None | |
def value(ploca, alpha, beta): | |
return -alphabeta(protivnik(igrajer), ploca, -beta, -alpha, depth-1, evaluate)[0] | |
moves = legalan_potez(igrajer, ploca) | |
if not moves: | |
if not bilokoji_lPotez(protivnik(igrajer), ploca): | |
return zavrsni_rezultat(igrajer, ploca), None | |
return value(ploca, alpha, beta), None | |
best_move = moves[0] | |
for move in moves: | |
if alpha >= beta: | |
break | |
val = value(napravi_potez(move, igrajer, list(ploca)), alpha, beta) | |
if val > alpha: | |
alpha = val | |
best_move = move | |
return alpha, best_move | |
def alphabeta_pretrazivac(depth, evaluate): | |
def strategy(igrajer, ploca): | |
return alphabeta(igrajer, ploca, MIN_VALUE, MAX_VALUE, depth, evaluate)[1] | |
return strategy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment