Ejemplo n.º 1
0
		/**
		 * To clear the Sudoku board.
		 */
		public void clearPuzzels() {
			for (int i = 0; i < BOARD_SIZE; i++)
				for (int j = 0; j < BOARD_SIZE; j++) {
					sudokuBoard[i, j] = CELL_EMPTY;
					emptyCellsPointer[i, j] = null;
				}
			for (int i = 0; i < BOARD_CELLS_NUMBER; i++)
				emptyCells[i] = new EmptyCell();
			emptyCellsNumber = 0;
			solvingState = SOLVING_STATE_NOT_STARTED;
			boardState = BOARD_STATE_EMPTY;
			solvedBoard = null;
			solutionPath = null;
			computingTime = 0;
			closedPathsCounter = 0;
			addMessage("(clearPuzzels) Clearing sudoku board - board is empty.", MSG_INFO);
		}
Ejemplo n.º 2
0
		/**
		 * Find digits that still can be used in a given empty cell.
		 * @param emptyCell Empty cell to search still free digits for.
		 */
		private void findDigitsStillFree(EmptyCell emptyCell) {
			emptyCell.setAllDigitsStillFree();
			for (int j = 0; j < BOARD_SIZE; j++) {
				int boardDigit = sudokuBoard[emptyCell.rowIndex, j];
				if (boardDigit != CELL_EMPTY)
					emptyCell.digitsStillFree[boardDigit] = DIGIT_IN_USE;
			}
			for (int i = 0; i < BOARD_SIZE; i++) {
				int boardDigit = sudokuBoard[i, emptyCell.colIndex];
				if (boardDigit != CELL_EMPTY)
					emptyCell.digitsStillFree[boardDigit] = DIGIT_IN_USE;
			}
			SubSquare sub = SubSquare.getSubSqare(emptyCell);
			/*
			 * Mark digits used in a sub-square.
			 */
			for (int i = sub.rowMin; i < sub.rowMax; i++)
				for (int j = sub.colMin; j < sub.colMax; j++) {
					int boardDigit = sudokuBoard[i, j];
					if (boardDigit != CELL_EMPTY)
						emptyCell.digitsStillFree[boardDigit] = DIGIT_IN_USE;
				}
			/*
			 * Find number of still free digits to use.
			 */
			emptyCell.digitsStillFreeNumber = 0;
			for (int digit = 1; digit < 10; digit++)
				if (emptyCell.digitsStillFree[digit] == DIGIT_STILL_FREE)
					emptyCell.digitsStillFreeNumber++;
		}
Ejemplo n.º 3
0
		/**
		 * Sub-square identification on the Sudoku board
		 * based on the cell position
		 * @param emptyCell   Cell object, including cell position
		 * @return             Sub-square left-top and right-bottom indexes.
		 */
		internal static SubSquare getSubSqare(EmptyCell emptyCell) {
			return getSubSqare(emptyCell.rowIndex, emptyCell.colIndex);
		}