I have been working on this for hours, and have done quite a bit of research. It seems I just cannot connect the dots in my head to understand this.

I am writing a tic tac toe type program, and need to implement and AI using a minimax algorithm. I know what the behind it is, and what it's designed to do, but just can't seem to figure out how to get it into my program. Heck, I went so far as to hire a tutor to help. After 3 hours with him today, and a lot of wasted cash, I am no closer. He had no idea what minimax was.

My game is similar to tic tac toe, except the board can be larger depending on what the user chooses. When someone scores, their pieces are removed from the board but the game continues.

I can't imagine recursing through all of those options, so I am just wanting the algorithm to find the next best scoring option. My board is a 2D array, where most of the examples I see deal with 1D arrays. I could use any help that you can give me.

The game works fine now for 2 human players.

Methods are written for checking board, clearing board, checking win etc. I guess I just don't understand how to recursively create new boards and return values on the moves.

This is what I have so far.

I guess I need to know how to use my methods to increase the value of position Value. I know, my question is a mess, sorry

/** minimax method to compute best possible computer move*/ public int[][] compMove(int[][]gameBoard, int boardSize, int playerNumber, int row, int col){ int bestMoveIndex = 0; int bestValue = +1000; int [][] bestMoves = new int[boardSize][boardSize]; for(int i = 0; i<boardSize; i++) for(int k = 0; k<boardSize; k++){ if(gameBoard[i][k] == 0 && playerNumber == 1) gameBoard[i][k] = 1; int value = maxSearch(gameBoard); if(value < bestValue){ bestValue = value; bestMoveIndex= 0; bestMoves[bestMoveIndex][k] = i; } else if(value == bestValue){ bestMoves[bestMoveIndex++][k] = i; gameBoard[i][k] = 0; } CompPlacePiece(bestMoves, i, k, playerNumber); } return gameBoard; } public int maxSearch(int[][]gameBoard, int playerNumber){ int positionValue = 0; return positionValue; }