anchal-agrawal / sudoku-solver

A Sudoku solver application written using the model-view-controller pattern

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sudoku-solver

A Java application that solves a Sudoku grid after the user enters an initial configuration. This application uses the MVC (model-view-controller) pattern. The GUI has 3 buttons - Solve, Reset and Undo last cell and a status label. The user can input numbers by clicking on cell buttons and pressing Solve. If the initial configuration is invalid (there are duplicate numbers in the same row/column/3x3 grid), the status label will display an error message. The Reset button clears all cells, and the Undo last cell button clears input cells one-by-one, starting from the last input cell.

Algorithm

The Sudoku-solving algorithm follows a backtracking approach:

  • Pick an unassigned (empty) cell. If all cells are filled, we're done.
  • Find possible candidate numbers for that cell.
  • Assign a candidate to that cell and recurse on the remaining grid.
  • If the candidate doesn't lead to a valid solution, try the next one.

Test Suite

There are 3 classes with several JUnit tests:

  • sudoku/tests/CellTests.java - tests for the Cell class's methods.
  • sudoku/tests/GridTests.java - tests for the Grid class's methods.
  • sudoku/tests/GameTests.java - test the solving algorithm.

All tests can be run with the sudoku/tests/TestSuite.java class.

Running the application

This repository can be imported as an Eclipse project. The sudoku/driver/Driver.java class can be run to launch the application.

Sample run

  • Initial GUI

  • Enter values

  • Press Solve

External libraries

The application uses the Apache Commons Lang library to check if the user input is not numeric.

About

A Sudoku solver application written using the model-view-controller pattern


Languages

Language:Java 100.0%