Hi everyone, my team and I are having difficulty implementing minimax for tic tac toe for our school's project.
I've tried referencing these links :
https://github.com/BrickSigma/Tic-Tac-Toe-Minimax
https://www.geeksforgeeks.org/minimax-algorithm-in-game-theory-set-3-tic-tac-toe-ai-finding-optimal-move/
But unfortunately none of these works.
my codes are as of below :
minimax function :
int minimax(char *board[ROW_SIZE][ROW_SIZE], int emptySpaces, int currentTurn, bool isMaximizer)
{
struct rowcol indexes[9];
getEmptySpaces(board, indexes);
if (isMaximizer)
{
int bestScore = -1000;
for (int i = 0; i < emptySpaces; i++)
{
board[indexes[i].row][indexes[i].col] = currentTurn == 0 ? "O" : "X";
bestScore = getMax(bestScore, minimax(board, emptySpaces - 1, currentTurn, !isMaximizer));
board[indexes[i].row][indexes[i].col] = " ";
}
return bestScore;
}
else
{
int bestScore = 1000;
for (int i = 0; i < emptySpaces; i++)
{
board[indexes[i].row][indexes[i].col] = currentTurn == 0 ? "O" : "X";
bestScore = getMin(bestScore, minimax(board, emptySpaces - 1, currentTurn, !isMaximizer));
board[indexes[i].row][indexes[i].col] = " ";
}
return bestScore;
}
}
Thank you everyone in advance 🙏
GitHub
A simple replica of tic-tac-toe using the minimax algorithm and raylib - GitHub - BrickSigma/Tic-Tac-Toe-Minimax: A simple replica of tic-tac-toe using the minimax algorithm and raylib