private void Start()
        {
            if (isOnlineGame)
            {
                if (PhotonNetwork.IsMasterClient)
                {
                    PlayerController tempController = new GameObject("PlayerController").AddComponent <PlayerController>();
                    tempController.mySymbol = Symbol.X;
                }
                else
                {
                    PlayerController tempController = new GameObject("PlayerController").AddComponent <PlayerController>();
                    tempController.mySymbol = Symbol.O;
                }
            }
            else
            {
                PlayerController tempController = new GameObject("AIController").AddComponent <PlayerController>();
                tempController.mySymbol = Symbol.O;
                tempController.isAI     = true;
                switch (TicTacToeUtility.GetDifficulty())
                {
                case Difficulty.Easy:
                    Debug.Log("Is easy");
                    tempController.difficulty = Difficulty.Easy;
                    break;

                case Difficulty.Normal:
                    Debug.Log("Is normal");
                    tempController.difficulty = Difficulty.Normal;
                    break;

                case Difficulty.Hard:
                    Debug.Log("Is hard");
                    tempController.difficulty = Difficulty.Hard;
                    break;

                default:
                    break;
                }


                tempController          = new GameObject("PlayerController").AddComponent <PlayerController>();
                tempController.mySymbol = Symbol.X;
            }

            OnGameReset?.Invoke();
            OnRematch?.Invoke();
            OnSymbolTurnStart?.Invoke(Symbol.X);

            photonView = GetComponent <PhotonView>();
        }
        private void OnSymbolTurnStart(Symbol currentSymbolTurn)
        {
            if (gameStateManager.CheckIfIsOnlineGame())
            {
                if (currentSymbolTurn == mySymbol)
                {
                    Debug.Log(gameObject.name + " is my turn");
                    gridManager.canvasGroup.interactable = true;
                }
                else
                {
                    Debug.Log(gameObject.name + " is enemy turn");
                    gridManager.canvasGroup.interactable = false;
                }
            }

            else if (currentSymbolTurn == mySymbol && isAI)
            {
                Debug.Log(gameObject.name + " is AI turn");
                gridManager.canvasGroup.interactable = false;

                switch (difficulty)
                {
                case Difficulty.Easy:
                    Vector2Int[] emptyCells = TicTacToeUtility.GetEmptyPositions(gridManager.grid);
                    if (emptyCells.Length > 0)
                    {
                        gridManager.GetGridButtonAtPosition(emptyCells[UnityEngine.Random.Range(0, emptyCells.Length)]).onClick.Invoke();
                    }
                    break;

                case Difficulty.Normal:
                    gridManager.GetGridButtonAtPosition(TicTacToeUtility.MiniMax(gridManager.grid, 2, true).position).onClick.Invoke();
                    break;

                case Difficulty.Hard:
                    gridManager.GetGridButtonAtPosition(TicTacToeUtility.MiniMax(gridManager.grid, 9, true).position).onClick.Invoke();
                    break;

                default:
                    break;
                }
            }
            else if (currentSymbolTurn == mySymbol)
            {
                Debug.Log(gameObject.name + " is Player turn");
                gridManager.canvasGroup.interactable = true;
            }
        }
        private void OnGridCellFilled(int[,] grid, int gridSize)
        {
            WinResult result = TicTacToeUtility.CheckWinner(grid, gridSize);

            switch (result.score)
            {
            case 1:
                Debug.Log("X - win");
                p1Score++;
                isGameOver = true;
                OnGameOver?.Invoke(result);
                break;

            case -1:
                Debug.Log("O - win");
                p2Score++;
                isGameOver = true;
                OnGameOver?.Invoke(result);
                break;

            case 0:
                if (!TicTacToeUtility.CheckForEmptyCells(grid))
                {
                    Debug.Log("Draw");
                    drawScore++;
                    isGameOver = true;
                    OnGameOver?.Invoke(result);
                }
                break;

            default:
                Debug.Log("Incorrect result");
                break;
            }
            if (!isGameOver)
            {
                SwitchSymbolTurn();
                OnSymbolTurnStart?.Invoke(currentSymbolTurn);
            }
            else
            {
                if (result.score == 0)
                {
                    SwitchSymbolTurn();
                }
                DOVirtual.DelayedCall(2f, () => Rematch());
            }
        }
 public void SaveSelectedDifficulty()
 {
     TicTacToeUtility.SaveDifficulty(difficulty);
 }