/// <summary>
 /// Iterate through all psoitions to see if they are equall for the current state
 /// </summary>
 /// <param name="board">The current board</param>
 /// <param name="positions">The given psoitions on the board</param>
 /// <param name="state">The kind of state to check</param>
 /// <returns></returns>
 private bool AreAll(Board board, Position[] positions, State state)
 {
     foreach (Position position in positions)
     {
         if (board.GetState(position) != state)
         {
             return(false);
         }
     }
     return(true);
 }
 public bool IsDraw(Board board)
 {
     for (int row = 0; row < 3; row++)
     {
         for (int column = 0; column < 3; column++)
         {
             if (board.GetState(new Position(row, column)) == State.undecided)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
        /// <summary>
        /// Check if it is a draw
        /// </summary>
        /// <param name="board">The current board</param>
        /// <returns></returns>
        public bool IsDraw(Board board)
        {
            for (int row = 0; row < 3; row++)
            {
                for (int column = 0; column < 3; column++)
                {
                    // If there is any undefined state on the board then the game is still playable
                    if (board.GetState(new Position(row, column)) == State.Undecided)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
 public void Render(Board board)
 {
     char[,] symbols = new char[3, 3];
     for (int row = 0; row < 3; row++)
     {
         for (int column = 0; column < 3; column++)
         {
             symbols[row, column] = SymbolFor(board.GetState(new Position(row, column)));
         }
     }
     Console.WriteLine($"{symbols[0, 0]}|{symbols[0, 1]}|{symbols[0, 2]}");
     Console.WriteLine("---+---+---");
     Console.WriteLine($"{symbols[1, 0]}|{symbols[1, 1]}|{symbols[1, 2]}");
     Console.WriteLine("---+---+---"); Console.WriteLine($"{symbols[0, 0]}|{symbols[0, 1]}|{symbols[0, 2]}");
     Console.WriteLine($"{symbols[2, 0]}|{symbols[2, 1]}|{symbols[2, 2]}");
 }
Example #5
0
        /// <summary>
        /// Render the board
        /// </summary>
        /// <param name="board">The current board</param>
        public void Render(Board board)
        {
            // Store symbols values on the board
            char[,] symbols = new char[3, 3];

            // Set states on the board
            for (int row = 0; row < 3; row++)
            {
                for (int column = 0; column < 3; column++)
                {
                    symbols[row, column] = SymbolFor(board.GetState(new Position(row, column)));
                }
            }

            // Write the board in the console window
            Console.WriteLine($" {symbols[0, 0]} | {symbols[0, 1]} | {symbols[0, 2]} | ");
            Console.WriteLine("===+===+===");
            Console.WriteLine($" {symbols[1, 0]} | {symbols[1, 1]} | {symbols[1, 2]} | ");
            Console.WriteLine("===+===+===");
            Console.WriteLine($" {symbols[2, 0]} | {symbols[2, 1]} | {symbols[2, 2]} | ");
        }
Example #6
0
 private static bool AreAll(Board board, Position[] positions, State state)
 {
     return(positions.All(position => board.GetState(position) == state));
 }