Compare commits
	
		
			2 commits
		
	
	
		
			e6cd5a2915
			...
			26df774ca3
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						26df774ca3 | ||
| 
							 | 
						270a9f381d | 
					 3 changed files with 23 additions and 6 deletions
				
			
		
							
								
								
									
										4
									
								
								Justfile
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								Justfile
									
										
									
									
									
								
							| 
						 | 
					@ -11,7 +11,7 @@ clean:
 | 
				
			||||||
    fd -td -I build -x rm -r
 | 
					    fd -td -I build -x rm -r
 | 
				
			||||||
 | 
					
 | 
				
			||||||
watch:
 | 
					watch:
 | 
				
			||||||
    watchexec -c -w app/src "just test && just run" 
 | 
					    watchexec -r -c -w app/src "just test && just run" 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
watchdoc:
 | 
					watchdoc:
 | 
				
			||||||
    watchexec -c -w app/src "just doc"
 | 
					    watchexec -r -c -w app/src "just doc"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,13 +26,13 @@ public class SudokuController {
 | 
				
			||||||
            public void actionPerformed(ActionEvent e) {
 | 
					            public void actionPerformed(ActionEvent e) {
 | 
				
			||||||
                // Solve the board
 | 
					                // Solve the board
 | 
				
			||||||
                boolean solved = model.solve();
 | 
					                boolean solved = model.solve();
 | 
				
			||||||
 | 
					                // Update the view
 | 
				
			||||||
 | 
					                view.updateView(model.getBoard());
 | 
				
			||||||
                if (!solved) {
 | 
					                if (!solved) {
 | 
				
			||||||
                    view.showErrorMessage("Could not solve the board.");
 | 
					                    view.showErrorMessage("Could not solve the board.");
 | 
				
			||||||
                    System.out.println("Could not solve the board.");
 | 
					                    System.out.println("Could not solve the board.");
 | 
				
			||||||
                    System.out.println(model.toString());
 | 
					                    System.out.println(model.toString());
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    // Update the view
 | 
					 | 
				
			||||||
                    view.updateView(model.getBoard());
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					@ -70,6 +70,13 @@ public class SudokuController {
 | 
				
			||||||
                if (newBoard != null) {
 | 
					                if (newBoard != null) {
 | 
				
			||||||
                    // Set the model
 | 
					                    // Set the model
 | 
				
			||||||
                    model.setBoard(newBoard);
 | 
					                    model.setBoard(newBoard);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    // Warn and clear if the board is not solvable
 | 
				
			||||||
 | 
					                    if(!model.isSolvable()) {
 | 
				
			||||||
 | 
					                        view.showErrorMessage("The board is not solvable.");
 | 
				
			||||||
 | 
					                        model.clear();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    // Update the view
 | 
					                    // Update the view
 | 
				
			||||||
                    view.updateView(model.getBoard());
 | 
					                    view.updateView(model.getBoard());
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
| 
						 | 
					@ -113,7 +120,7 @@ public class SudokuController {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // If the input is invalid, value < 0 indicates parse error
 | 
					            // If the input is invalid, value < 0 indicates parse error
 | 
				
			||||||
            if (!model.isLegal(row, col, value) || value < 0) {
 | 
					            if (value != 0 && !model.isLegal(row, col, value) || value < 0) {
 | 
				
			||||||
                value = 0;
 | 
					                value = 0;
 | 
				
			||||||
                view.showErrorMessage("Invalid input. Try again.");
 | 
					                view.showErrorMessage("Invalid input. Try again.");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,7 +29,12 @@ public class Solver implements SudokuSolver {
 | 
				
			||||||
    /** Resets the board to all zeros */
 | 
					    /** Resets the board to all zeros */
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void clear() {
 | 
					    public void clear() {
 | 
				
			||||||
        board = new int[9][9];
 | 
					        for (int[] row : board) {
 | 
				
			||||||
 | 
					            for (int i = 0; i < row.length; ++i) {
 | 
				
			||||||
 | 
					                row[i] = 0;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        // board = new int[9][9];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* {@inheritDoc} */
 | 
					    /* {@inheritDoc} */
 | 
				
			||||||
| 
						 | 
					@ -144,6 +149,11 @@ public class Solver implements SudokuSolver {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Ihe the number is already present in the cell
 | 
				
			||||||
 | 
					        if (board[row][col] == num) {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Check both the row and column
 | 
					        // Check both the row and column
 | 
				
			||||||
        for (int i = 0; i < 9; i++) {
 | 
					        for (int i = 0; i < 9; i++) {
 | 
				
			||||||
            if (board[row][i] == num || board[i][col] == num) {
 | 
					            if (board[row][i] == num || board[i][col] == num) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue