Tic Tac Toe Grand AI not random

The project:

To make a tic tac toe game little more fun to play. There are 2 main types of mode one is classic version which is 3x3 grid playing field and it has two form of play Human V Human, Human V AI. this classic version is running fine no problem in AI moves.

2nd version is what I am calling is Grand Tic Tac Toe which is basically 9 x 9 grid playing field but it is actually 9 games of classic Tic Tac Toe being played simultaneously so we can say it is a set based game to win the grand version we have to play in all nine games and when we win one set that set is marked with your icon X or O so now that set is one point of grid so now we need to win more sets to make a line of three sets.

Code:

Android Studio is the platform used for writing the app. code is too long to be displayed here so i am attaching the github link of my project https://github.com/AUKNiazi/GrandTicTacToe

file which has the code for Grand Tic Tac Toe https://github.com/AUKNiazi/GrandTicTacToe/blob/master/java/com/example/auk01/grandtictactoe/TicTacToeGame.java

Problem: when a human player wins first set the AI will no longer move Randomly and will not block player’s wining moves. AI will start placing its move from the top most row left side first available point and will keep moving to its right and when the top row ends it will move to 2nd row first available left point and will keep placing its move to the next right.

screen recording of the problem:

it is also on the github page file called
tictactoe.mp4

// Return the best move for the computer to make. You must call setMove()
// to actually make the computer move to that location.
public int getComputerMove(){
    int move;

    // First see if there's a move O can make to win
    for (int i = 0; i < getBOARD_SIZE(); i++)
    {
        if (mBoard[i] != PLAYER_ONE && mBoard[i] != PLAYER_TWO && mBoard[i] == EMPTY_SPACE)
        {
            char curr = mBoard[i];
            mBoard[i] = PLAYER_TWO;
            if ( checkForWinner() == 3)
            {
                setMove(PLAYER_TWO, i);
                return i;
            }
            else
                mBoard[i] = curr;
        }
    }

    // See if there's a move O can make to block X from winning
    for (int i = 0; i < getBOARD_SIZE(); i++)
    {
        if (mBoard[i] != PLAYER_ONE && mBoard[i] != PLAYER_TWO && mBoard[i] == EMPTY_SPACE)
        {
            char curr = mBoard[i];
            mBoard[i] = PLAYER_ONE;
            if ( checkForWinner() == 2)
            {
                setMove(PLAYER_TWO, i);
                return i;
            }
            else
                mBoard[i] = curr;
        }
    }

    // Generate random move
    do
    {
        move = mRand.nextInt(getBOARD_SIZE());
    } while (mBoard[move] == PLAYER_ONE || mBoard[move] == PLAYER_TWO);

    setMove(PLAYER_TWO, move);
    return move;
}

I think watching this video
will help you out here

Problem: when a human player wins first set the AI will no longer move Randomly and will not block player’s wining moves. AI will start placing its move from the top most row left side first available point and will keep moving to its right and when the top row ends it will move to 2nd row first available left point and will keep placing its move to the next right.
Possible sollution: Use a data structure
And use the 1 0 -1 system
where 1 is a win
0 is a tie
-1 is a losse
The data structure will help to predict the human next move and use a nummeric system that you can set with number. It thinks like a machine and winning lossing a machine simply doesn’t understand. But if you insert the information the AI can think of its next move.
You can also use a database for it but, beware there are 200k+ possible moves in Tic Tac Toe so the program can get HUGE! specially when you add rows the ammout of move it has to go through can cost quite some data.

I’m wondering, off the top of my head, if there is on issue of scope, so to speak. If the large board state data is influencing the small game board choices, it could be that the AI is attempting to choose a location as if the small and large game state data was mixed in some way?

this is in python and my app is in java will this help me.

every thing works if AI wins there is no change in the random moves and AI will still block human player from winning. only if a human player wins then AI goes haywire . i am guessing there is very little problem which somehow i am not able to pin-point it.

kind of something like that maybe what were in the code have i done that