// ITI1120 A 4
// Names: Daniel Amyot, 1234567
//        Diana Inkpen, 7654321
// Library class for Sudoku

import javax.swing.JOptionPane;

public class SudokuLib {
  
  // Q5: TO COMPLETE  
  // METHOD verifyGuess: verifies if the guess would result is a valid sudoku grid
  // GIVENS: the row, the column, and the value to insert (the guess)  
  //         the sudoku grid and its constraints, 
  //         a boolean value indicating if we need to display an error message 
  //          (invoked with true in the program, with false in the tests)
  public static boolean verifyGuess(int row, int col, int move, int[][] sudoku, boolean[][] constraints, boolean messages) 
  {
    // DECLARATION OF VARIABLES / DATA DICTIONNARY
    boolean result; // RESULT: true if the guess does not make the grid invalid
    int pos;        // INTERMEDIATES: position in the row or column
    
    // BODY OF THE ALGORITHM

    result = true;
    
    // Does the player try to change one of the initial values?
    if (constraints[row][col]) 
    {
      if (messages)
        JOptionPane.showMessageDialog(null, "You cannot modify an initial value (in red)");
      result = false;
    }
    else
    {
       ; // TO COMPLETE!
    }
    
    // RETURN RESULT
    return result;
  }

  // Q4: TO COMPLETE
  // METHOD generateSudoku: randomly chooses one sudoku grid from the 
  // predefined ones, executes a random number of rotations, 
  // updates the constraints, and returns a sudoku grid
  // MODIFIEDS: constraints
  public static int[][] generateSudoku(boolean[][] constraints) 
  {
    // DECLARATION OF VARIABLES / DATA DICTIONNARY

    // BODY OF THE ALGORITHM



    // RETURN RESULT
    return sudokuGrids()[3]; // TO REPLACE!
  }

  // Q3: TO COMPLETE
  // METHOD generateConstraints: modifies the matrix of constraints  
  // that indicates by true a position in the sudoku grid
  // where there is a value that is different from 0 (and by false if = 0)
  // GIVENS: a matrix of integers representing a sudoku grid
  // MODIFIEDS: a matrix of boolean constraints
  public static void generateConstraints(int[][] sudoku, boolean[][] constraints)
  {
    // DECLARATION OF VARIABLES / DATA DICTIONNARY
    
    // BODY OF THE ALGORITHM


    
    // RETURN RESULT: NONE
  }

  // Q2: TO COMPLETE
  // METHOD solved: Determine if the grid was entirely solved
  // GIVENS: A matrix of integers representing the sudoku
  // ASSUMPTIONS: the sudoku contains 9x9 digits between 0 and 9 and it is not invalid
  public static boolean solved(int[][] sudoku)
  {
    // DECLARATION OF VARIABLES / DATA DICTIONNARY
    
    // BODY OF THE ALGORITHM


    
    // RETURN RESULT
    return false; // TO REPLACE!
  }
  
  // METHOD sudokusGrids: returns a list of initial Sudoku configurations (9x9).
  private static int[][][] sudokuGrids()
  {
    int[][][] grids; // array of arrays! 
    
    grids = new int[][][]
    {
      // 1st configuration, very easy...           
      { 
        {0, 2, 7, 4, 3, 5, 9, 6, 8},        
        {5, 9, 6, 7, 8, 2, 4, 1, 3},        
        {4, 3, 8, 9, 6, 1, 7, 2, 5},        
        {2, 5, 1, 8, 4, 3, 6, 9, 7},        
        {3, 8, 9, 6, 2, 7, 5, 4, 1},        
        {6, 7, 4, 1, 5, 9, 8, 3, 2},        
        {7, 6, 2, 3, 9, 8, 1, 5, 4},        
        {8, 4, 3, 5, 1, 6, 2, 7, 9},        
        {9, 1, 5, 2, 7, 4, 3, 8, 6},        
      }, 
        // 2nd configuration, easy...   
      { 
        {5, 4, 0, 6, 0, 0, 3, 0, 0},        
        {0, 0, 0, 3, 1, 0, 0, 0, 4},        
        {0, 3, 9, 0, 7, 0, 1, 0, 0},        
        {0, 0, 0, 8, 0, 0, 0, 2, 1},        
        {0, 0, 0, 0, 0, 1, 6, 8, 3},        
        {2, 1, 8, 0, 3, 0, 0, 0, 0},        
        {1, 9, 0, 0, 0, 0, 4, 6, 0},        
        {0, 8, 0, 1, 0, 0, 0, 3, 0},        
        {6, 7, 3, 0, 4, 8, 0, 0, 0},        
      }, 
      { 
        // 3rd configuration, realistic...
        {0, 0, 0, 0, 0, 0, 0, 1, 0},
        {1, 5, 0, 2, 0, 7, 0, 0, 4},
        {0, 4, 0, 1, 0, 0, 0, 5, 8},
        {7, 0, 0, 6, 0, 0, 0, 0, 1},
        {0, 2, 4, 0, 8, 1, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 5, 0, 7},
        {4, 0, 0, 0, 3, 2, 0, 7, 0},
        {0, 0, 0, 4, 0, 0, 0, 0, 0},
        {6, 7, 2, 0, 1, 0, 4, 3, 0}
      }, 
        // 4th configuration, very difficult...           
      { 
        {5, 2, 0, 0, 0, 0, 0, 0, 0},        
        {0, 7, 0, 0, 0, 0, 0, 0, 1},        
        {9, 0, 0, 0, 0, 0, 0, 0, 0},        
        {2, 0, 5, 7, 0, 8, 4, 0, 0},        
        {7, 0, 0, 0, 4, 0, 8, 0, 0},        
        {0, 8, 0, 9, 6, 2, 0, 0, 5},        
        {8, 0, 0, 0, 7, 0, 0, 0, 4},        
        {6, 0, 2, 3, 0, 0, 0, 7, 0},        
        {0, 0, 0, 0, 0, 0, 6, 0, 0},                
      }
    };
    
    // RETURN RESULT
    return grids;
  }
  
}
