public void SetAIMove() { CellIndex bestMove = tt.FindNextMove(); tt.SetMove(bestMove.Row, bestMove.Col, true); //mCells[bestMove.Row * 3 + bestMove.Col].Activate(true); StartCoroutine(Coroutine_OnMakeMove(0.2f, bestMove.Row, bestMove.Col, true)); }
public CellIndex FindNextMove() { int bestVal = -1000; CellIndex bestMove = new CellIndex(); bestMove.Row = -1; bestMove.Col = -1; // Traverse all cells, evaluate minimax function // for all empty cells. And return the cell // with optimal value. for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { // Check if cell is empty if (mBoard[i, j] == ' ') { // Make the move mBoard[i, j] = computer; // compute evaluation function for this // move. int moveVal = Minimax(mBoard, 0, false); // Undo the move mBoard[i, j] = ' '; // If the value of the current move is // more than the best value, then update // best/ if (moveVal > bestVal) { bestMove.Row = i; bestMove.Col = j; bestVal = moveVal; } } } } Debug.Log("The value of the best Move is: " + bestVal); return(bestMove); }