how to implement alpha-beta pruning (tic tac toe)
-
hello everyone, i made a tic tac toe in C language, using the minimax algorithm but i have some problem when i try to play with larger matrix more than 3x3 for example 4x4 and my program go out of memory. So i search in the net and i discover the aplpha-beta pruning that reduce the computional coast and so i can play with 4x4 matrix whiteout problems but i have not idea to implement this algorithm to my minimax. if there is a person who want to help me i would be grateful. sorry for my bad english but i am italian :(( i can post my code if you want
-
hello everyone, i made a tic tac toe in C language, using the minimax algorithm but i have some problem when i try to play with larger matrix more than 3x3 for example 4x4 and my program go out of memory. So i search in the net and i discover the aplpha-beta pruning that reduce the computional coast and so i can play with 4x4 matrix whiteout problems but i have not idea to implement this algorithm to my minimax. if there is a person who want to help me i would be grateful. sorry for my bad english but i am italian :(( i can post my code if you want
-
You could start (if you haven't already done) with the Wikipedia's article on the subject: Alpha–beta pruning[^].
hi, i read the article on wikipedia and i understand it but the problem is that i don't know how to implement it to my minimax :(( here is my minimax if want to give me an idea .. ;)
int miniMax(char wnr, int deep)//Minimax
{
if (controlloVincita(2))//control win
return INT_MAX;
if (endgame())
return INT_MIN;
int i, j, res, tmp;if (wnr == 1)//se giocatore massimizzante { res = 1; for (i = 0;ires || (tmp == INT\_MAX)) res = tmp; BOARD\[i\]\[j\] = 0; } } } return res;
}
int get_next_move(unsigned int *i, unsigned int *j)
{
int max = INT_MIN, mi = 1, mj = 1, t;
int alfa = INT_MIN, beta = INT_MAX;
for (*i = 0;*imax)//
{
max = t;
mi = *i;
mj = *j;
}
BOARD[*i][*j] = 0;
}BOARD\[mi\]\[mj\] = 2;//save the computer move \*i = mi; \*j = mj; return 1;
}