Пример #1
0
        private bool isWinner(string playerSymbol)
        {
            // Check Rows
            if (GameBoard.Any(Row => Row.All(Cell => Cell == playerSymbol)))
            {
                return(true);
            }

            // Check Columns
            for (int i = 0; i <= 2; i++)
            {
                if (GameBoard.All(Row => Row[i] == playerSymbol))
                {
                    return(true);
                }
            }

            // Check Diagonals
            string[][] Diagonals = new string[2][] { new string[3], new string[3] };
            for (int i = 0; i <= 2; i++)
            {
                Diagonals[0][i] = GameBoard[i][i];
                Diagonals[1][i] = GameBoard[i][2 - i];
            }
            if (Diagonals.Any(Diagonal => Diagonal.All(Cell => Cell == playerSymbol)))
            {
                return(true);
            }

            return(false);
        }