when i apply minmax only to my connect4 game it get right results untill depth 7 and when i apply pruning to increase depth it get wrong results , i need a help to kno what is wrong with my logic or implementation?
private int score()
{
int winner = check_Winner(); // return 1 if player win or 2 when pc win or 0
if (winner == 1) return 10;
else if (winner == 2) return -10;
else return 0;
}
public int MinMax(int player_num, int depth, int alpha, int beta)
{
List<pair> possiple_moves = new List<pair>();
get_possible_moves( possiple_moves);
//================================================
int score_so_far = score();
if (possiple_moves.Count == 0 || score_so_far != 0 || depth == 10)// terminal case
return score_so_far;
//================================================
if (player_num == 1)// maxmize
{
int max_score = int.MinValue, temp = 0;
foreach (pair move in possiple_moves)
{
cells[move.x, move.y].player_num = 1;
temp = MinMax(2, depth + 1, alpha, beta);
if (temp > max_score)
{
max_score = temp;
pc_move = move;
}
cells[move.x, move.y].player_num = 0;
alpha = Math.Max(alpha, max_score);
if (beta <= alpha)
break;
}
return max_score;
}
//==========================
else
{
int min_score = int.MaxValue, tmp = 0;
foreach (pair move in possiple_moves)
{
cells[move.x, move.y].player_num = 2;
tmp = MinMax(1, depth + 1, alpha, beta);
if (tmp < min_score)
{
min_score = tmp;
pc_move = move;
}
cells[move.x, move.y].player_num = 0;
beta = Math.Min(beta, min_score);
if (beta <= alpha)
break;
}
return min_score;
}
}