#Minimax for Tic Tac Toe using Raylib

1 messages · Page 1 of 1 (latest)

balmy sigil
#

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

lyric lynxBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

lyric lynxBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.