Page 1 of 1

Sudoku IV - Brute Force GUI A GUI to compare Brute Force Rate Topic: -----

#1 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Posted 20 October 2010 - 08:50 PM

In tutorial Sudoku II - Brute Force we saw how to solve a Sudoku problem using the Brute Force

The class posted here is just a main() method that invokes classes prosted in previous tutorials.

The main() method creates 2 Grid objects with the same Sudoku problem coming from the Problems.class.

It creates 2 GridGuiOne object and put them together in a JFrame which has a GridLayout(1,2).

The 2 BruteForce class objects are created. Then their solveWithGui() method is invoked to solve by ButeForce the same problem. One using scanning the Sudoku grid from cell[0,0] to cell[8,8] the other by solving the problem in reversed order from cell[8,8] to cell[0,0].

The main method calls the Problems class setProblem3() method to fill the 2 grids. This is a very simple to solve Sudolu problem with most of the cells already filled.

You can also try using setProblem1() method, that will be longer, or if you are really patient, use setProblem2() method which load one of the "worst case" Sudoku problem to be fixed by the Brute Force method... that might take a while.

You can also edit the file to change at which speed the GUI is updated. The line

timer = new Timer(100, this);

says to refresh the GUI 10 times a second. You an try to lower down to 20 times a second using

timer = new Timer(50, this);
import javax.swing.*;
import java.awt.*;
 * A Demo of the Brute Force solving with a GUI
 * Two GidGuiOne will be created with the same problem
 * One Brute force will be used to fix the problem in order the other in reverse 
 * We will see how the cells are updated
public class BruteForceGui {
	 * To test the Grid
	public static void main(String[] atgs) {
		// create a JFrame to hold the Grid
		JFrame frame = new JFrame("Demo with two different solvers running a different way");
		// Build a Grid of size 9
		Grid grid1 = new Grid(9);
		Grid grid2 = new Grid(9);
		// load the grid with predefined problem
		// build a GridGuiOne for each Grid object
		GridGuiOne ggo1 = new GridGuiOne(grid1);
		GridGuiOne ggo2 = new GridGuiOne(grid2);
		// add the Grid to the Frame
		frame.setLayout(new GridLayout(1,2, 20, 20));
		// make it visible
		// build two BruteForce object
		BruteForce bf1 = new BruteForce(grid1);
		BruteForce bf2 = new BruteForce(grid2);
		// start the solving

The next turorials will deal on how create a Sudoku grid.
How to clear already filled cells until the solution does not become unique.

Is This A Good Question/Topic? 2
  • +

Page 1 of 1