Exemplo n.º 1
0
 /// <summary>
 /// Cpus the move.
 /// </summary>
 /// <param name="boardPositions">The board positions.</param>
 /// <param name="choosingCharacter">The choosing character.</param>
 /// <param name="index">The index which helps in choosing character from array for cpu</param>
 public static void CpuMove(char[] boardPositions, char[] choosingCharacter, int index)
 {
     // while loop moves until position is entered by cpu in array and displayed in board.
     while (true)
     {
         int positionEnteredByCpu;
         int positionForWinning = CpuMoveForWinning(boardPositions, choosingCharacter);
         //if position for winning is 0, then their is no position at which cpu can win or block position for win of user.
         if (positionForWinning == 0)
         {
             //calls the method to enter character at corner position, at middle and if no case is satisfied, randomly - by cpu.
             positionEnteredByCpu = TicTacToe.FillingVoidPositionByCpu(boardPositions);
         }
         //calls the method and returns the value where either the cpu is winning or blocking position for winning of user.
         else
         {
             positionEnteredByCpu = positionForWinning;
         }
         //adding character in array using position returned from methods and displaying in boards.
         if (boardPositions[positionEnteredByCpu] == ' ')
         {
             boardPositions[positionEnteredByCpu] = choosingCharacter[index % 2];
             TicTacToe.Board(boardPositions);
             break;
         }
     }
 }