Example #1
0
        public bool HasWinner(ITicTacToeBoard ticTacToeBoard)
        {
            var lastPlayer  = ticTacToeBoard.GetPlayedCells().Last().State;
            var coordinates = ticTacToeBoard.GetPlayedCells().Where(move => move.State == lastPlayer)
                              .Select(move => move.Coordinates)
                              .ToList();
            var hasWinningLine = new List <bool>
            {
                CheckForWinningRowWithSameDepth(coordinates),
                CheckForWinningRowWithDifferentDepth(coordinates),
                CheckForWinningColumnWithSameDepth(coordinates),
                CheckForWinningColumnWithDifferentDepth(coordinates),
                CheckForWinningDepth(coordinates),
                CheckForWinningVerticalPrimaryDiagonalLineWithSameDepth(coordinates),
                CheckForWinningVerticalSecondaryDiagonalLineWithSameDepth(coordinates),
                CheckForWinningVerticalPrimaryDiagonalLineWithDifferentDepth(coordinates),
                CheckForWinningVerticalSecondaryDiagonalLineWithDifferentDepth(coordinates)
            };

            return(hasWinningLine.Contains(true));
        }
 private static void RenderOneLayerOfBoard(ITicTacToeBoard board, int depth)
 {
     for (var row = 0; row < board.GetBoardSize(); row++)
     {
         for (var col = 0; col < board.GetBoardSize(); col++)
         {
             var symbolOfCurrentPosition = board.GetPlayedCells()
                                           .Where(cell => cell.Coordinates.Row == row && cell.Coordinates.Column == col && cell.Coordinates.Depth == depth)
                                           .Select(move => move.State);
             if (symbolOfCurrentPosition.Any())
             {
                 Console.Write(" " + symbolOfCurrentPosition.First() + " ");
             }
             else
             {
                 Console.Write(" . ");
             }
         }
         Console.WriteLine(Environment.NewLine);
     }
     Console.Write(Environment.NewLine);
 }
Example #3
0
 private bool IsDrawGame()
 {
     return(_ticTacToeBoard.GetPlayedCells().Count == _ticTacToeBoard.GetBoardSize() * _ticTacToeBoard.GetBoardSize() * _ticTacToeBoard.GetBoardSize());
 }