Example #1
0
 // construct standard tic-tac-toe board size of 3x3
 public TicTacToe()
 {
     for (int pi = 0; pi < (int)PlayerNumEnum.PLAYER_MAX; pi++)
     {
         PlayerNumEnum p = (PlayerNumEnum)pi;
         this.RowScores[p]  = new List <int>(new int[dimensions]);
         this.ColScores[p]  = new List <int>(new int[dimensions]);
         this.DiagScores[p] = new List <int>(new int[2]);
     }
 }
Example #2
0
 // Set the position of the users token, but does not check if the space was already taken
 public void SetUserPosition(PlayerNumEnum player, int row, int col)
 {
     if (row < dimensions && col < dimensions && player < PlayerNumEnum.PLAYER_MAX)
     {
         RowScores[player][row]++;
         ColScores[player][col]++;
         if (row == col)
         {
             DiagScores[player][0]++;
         }
         if (row + col == dimensions - 1)
         {
             DiagScores[player][1]++;
         }
     }
     else
     {
         throw new ArgumentOutOfRangeException(ArgumentOutOfRangeMessage);
     }
 }
Example #3
0
        // Determines which player was the winner
        public PlayerNumEnum GetWinner()
        {
            PlayerNumEnum winner = PlayerNumEnum.PLAYER_MAX;

            for (int pi = 0; pi < (int)PlayerNumEnum.PLAYER_MAX; pi++)
            {
                PlayerNumEnum p = (PlayerNumEnum)pi;
                for (int index = 0; index < dimensions; index++)
                {
                    if (RowScores[p][index] == dimensions ||
                        ColScores[p][index] == dimensions)
                    {
                        return(p);
                    }
                }
                if (DiagScores[p][0] == dimensions ||
                    DiagScores[p][1] == dimensions)
                {
                    return(p);
                }
            }

            return(winner);
        }