Esempio n. 1
0
        public string GetWinner()
        {
            var allPossibilities = getRowPossibilities()
                                   .Union(getColumnPossibilities())
                                   .Union(getCrossLinePossibilities());

            const int MinimumRequiredCharacters = 3;
            var       winnerSpot = allPossibilities
                                   .Where(it => it.Length == MinimumRequiredCharacters)
                                   .FirstOrDefault(it => it.All(c => c == it.First()));

            var winnerSymbol = winnerSpot?.First().ToString();

            const string XSymbol = "X";
            const string OSymbol = "O";

            if (winnerSymbol == XSymbol)
            {
                XScore++;
            }
            else if (winnerSymbol == OSymbol)
            {
                OScore++;
            }
            else
            {
                var anyEmptySpace = Slots.Cast <string>().Any(it => it == null);
                IsDraw = !anyEmptySpace;
            }

            return(winnerSymbol);
        }
Esempio n. 2
0
        public bool Place(string symbol, int row, int column)
        {
            Slots[row, column] = symbol;

            var isEvenNumber = Slots.Cast <string>().Count(it => it != null) % 2 == 0;

            CurrentTurn = isEvenNumber ? "X" : "O";

            return(true);
        }