jsam
1/30/2014 - 4:17 PM

[DSTG] Zadatak 5.

[DSTG] Zadatak 5.

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