Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * proves if the boad is valide after the rules for sudoku.
- *
- * @return boolean if the board is valide
- */
- public boolean isValid() {
- return (this.isRowValid() & this.isComValid() & this.isGridValid());
- }
- /**
- * proves if the rows is valide after the rules for sudoku.
- *
- * @return boolean if the rows is valide
- */
- public boolean isRowValid() {
- for (int col9 = 0; col9 < 9; col9++) {
- for (int row9 = 0; row9 < 9; row9++) {
- for (int row2 = 0; row2 < 9; row2++) {
- if (getValueAt(row9, col9) != -1) {
- if ((getValueAt(row9, col9) == getValueAt(row2, col9)) && (row9 != row2)) {
- return false;
- }
- }
- }
- }
- }
- return true;
- }
- /**
- * proves if the colums is valide after the rules for sudoku.
- *
- * @return boolean if the colums is valide
- */
- public boolean isComValid() {
- for (int row0 = 0; row0 < 9; row0++) {
- for (int col0 = 0; col0 < 9; col0++) {
- for (int col2 = 0; col2 < 9; col2++) {
- if (getValueAt(row0, col0) != -1) {
- if ((getValueAt(row0, col0) == getValueAt(row0, col2)) && (col0 != col2)) {
- return false;
- }
- }
- }
- }
- }
- return true;
- }
- /**
- * prooves if one spesific 3 times 3 grid on the board is valid.
- *
- * @param x for the cordinat of the upper left corner of the grid.
- * @param y for the cordinat of the upper left corner of the grid.
- * @return boolean if that one grid its called on is valid.
- */
- /*
- * public boolean isOneGridValid(int x, int y) { Set<Integer> set = new
- * HashSet<>(); for (int i = 1; i < 10; i++) set.add(i); set.add(-1); for (int
- * row = x; row < x + 4; row++) { for (int col = y; col < y + 4; col++) { if
- * (!set.contains(getValueAt(row, col))) { return false; }
- * set.remove(getValueAt(row, col)); set.add(-1); } } return true; }
- */
- /**
- * look if there are no dobble number in one 3 times 3 grid.
- *
- * @param x coordiate for upper left corner of grid
- * @param y coordiate for upper left corner of grid
- * @return if one grid is valid
- */
- public boolean isOneGridValid(int x, int y) {
- for (int col = y; col <= y + 3; col++) {
- for (int row = x; row <= x + 3; row++) {
- for (int col1 = col; col1 <= y + 2; col1++) {
- for (int row1 = row; row1 <= x + 2; row1++) {
- if (getValueAt(row, col) != -1) {
- if ((getValueAt(row, col) == getValueAt(row1, col1)) && ((col != col1) && (row != row1))) {
- return false;
- }
- }
- }
- }
- }
- }
- return true;
- }
- /**
- * this mathod proves if the number is the grids are valid.
- *
- * @return boolean if the whole grid is valid.
- */
- public boolean isGridValid() {
- for (int row6 = 0; row6 < 7; row6 += 3) {
- for (int col6 = 0; col6 < 7; col6 += 3) {
- if (!this.isOneGridValid(row6, col6))
- // if (!this.isOneGridValid(row6, col6))
- return false;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement