Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package csc143.sudoku;
- import javax.swing.*;
- import csc143.sudoku.*;
- import java.awt.*;
- import java.util.*;
- /**
- * @author Vita Wiebe, implementing code by Dan Jinguji
- * @version PAx: Sudoku Serialization and Make-Up
- * A class extending SudokuCore, which in turn extends
- * SudokuBase.
- */
- public class SudokuModel extends SudokuCore {
- /** Our class constructor.
- * @param int r, int c
- */
- public SudokuModel(int r, int c) {
- super(r, c);
- }
- // Need to go thru cellCoordinates[][] row index # n and determine
- // whether row is complete, incomplete, or contains duplicates (error)
- public State getRowState(int n) {
- // Create a copy of grid[], our superclass's array for holdinig
- // the values of each cell on the board.
- int gridSorted[] = Arrays.copyOf(super.grid);
- // Sort the copy of grid[] in ascending order so elements
- // can be easily compared.
- Arrays.sort(gridSorted);
- // columns are total number for this game board
- int columns = c;
- for(int col = 1; col < columns; col++) {
- if(super.getValue(n, col) == 0) {
- return State.INCOMPLETE;
- } else if(super.getValue(n, col) == (super.getValue(n, col - 1))) {
- return State.ERROR;
- } else {
- return State.COMPLETE;
- }
- }
- }
- public State getColumnState(int n) {
- // Create a copy of grid[], our superclass's array for holdinig
- // the values of each cell on the board.
- int gridSorted[] = Arrays.copyOf(super.grid);
- // Sort the copy of grid[] in ascending order so elements
- // can be easily compared.
- Arrays.sort(gridSorted);
- // Rows is the total number of rows on the board
- int rows = r;
- for(int row = 1; row < rows; row++) {
- if(super.getValue(n, col) == 0) {
- return State.INCOMPLETE;
- } else if(super.getValue(n, col) == (super.getValue(n, col - 1))) {
- return State.ERROR;
- } else {
- return State.COMPLETE;
- }
- }
- }
- public State getRegionState(int n) {
- return State.ERROR;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement