Code Library Of Others/sgtlaugh/Alpha Beta Pruning.cpp
int backtrack(struct node cur, int i, int p, int alpha, int beta){
    if (i == n){
        return evaluate(cur);
    }

    int j, k, x;
    vector <struct node> ar = transition(cur, deck[i], p);

    for (j = 0; j < ar.size(); j++){
        x = backtrack(ar[j], i + 1, p ^ 1, alpha, beta);
        if (p == 0 && x > alpha) alpha = x; /// First player will maximize his score
        if (p == 1 && x < beta) beta = x; /// Second player will minimize his score
        if (alpha >= beta) break;
    }

    if (p == 0) return alpha;
    return beta;
}
/// alpha = maximum score maximizing player (p = 0) is assured so far
/// beta = minimum score minimizing player (p = 1) is assured so far
alpha = maximum score maximizing player (p = 0) is assured so far
beta = minimum score minimizing player (p = 1) is assured so far
alpha = maximum score maximizing player ( p = 0 ) is assured so far beta = minimum score minimizing player ( p = 1 ) is assured so far
int backtrack(struct node cur, int i, int p, int alpha, int beta){
    if (i == n){
        return evaluate(cur);
    }
    int j, k, x;
    vector <struct node> ar = transition(cur, deck[i], p);
    for (j = 0; j < ar.size(); j++){
        x = backtrack(ar[j], i + 1, p ^ 1, alpha, beta);
        if (p == 0 && x > alpha) alpha = x; 
        if (p == 1 && x < beta) beta = x; 
        if (alpha >= beta) break;
    }
    if (p == 0) return alpha;
    return beta;
}
int backtrack ( struct node cur , int i , int p , int alpha , int beta ) { if ( i == n ) { return evaluate ( cur ) ; } int j , k , x ; vector < struct node > ar = transition ( cur , deck [ i ] , p ) ; for ( j = 0 ; j < ar . size ( ) ; j ++ ) { x = backtrack ( ar [ j ] , i + 1 , p ^ 1 , alpha , beta ) ; if ( p == 0 && x > alpha ) alpha = x ; if ( p == 1 && x < beta ) beta = x ; if ( alpha >= beta ) break ; } if ( p == 0 ) return alpha ; return beta ; }
alpha = maximum score maximizing player (p = 0) is assured so far
beta = minimum score minimizing player (p = 1) is assured so far
alpha = maximum score maximizing player ( p = 0 ) is assured so far beta = minimum score minimizing player ( p = 1 ) is assured so far
/// First player will maximize his score /// Second player will minimize his score