Java Reference
In-Depth Information
implemented to complete the Sudoku game. It revolves around the ability to ran-
domly create new Sudoku puzzles and to provide solutions for them.
In conjunction with the popularity of Sudoku, many have put forth algorithms
for creating and solving Sudoku puzzles. With this in mind, we had the option of
either reinventing the wheel or leveraging the work that's been done already in
puzzle generation. In all honesty, there's no real advantage to writing a Sudoku
puzzle generator in JavaFX. It could have just as easily and effectively been writ-
ten in any of the myriad of available high-level programming languages. So why
not find what's out there, and see how easily it could be integrated into our appli-
cation? Code reuse and, in particular, integration with Java, arguably the largest
development community on the planet, are key design characteristics of JavaFX.
Sourceforge.net is a well-known centralized repository for open source software
projects. At that location, we found a Sudoku application located under the fol-
lowing URL:
http://sourceforge.net/projects/playsudoku/
This project is a complete program written in Java, including a Swing-based user
interface. Our interest was solely in its capability to create new Sudoku puzzles,
so we took a subset of the source code, specifically the classes found under the
net.sourceforge.playsudoku package, and integrated them into our application.
The integration effort was straightforward and involved two primary tasks:
1. Figuring out what methods need to be called to generate a new Sudoku
puzzle.
2. Determining if the data structures used by the Java application can be
directly used with JavaFX.
We'll handle the second task first and use our solution there as part of the overall
process needed to generate a new puzzle.
Delving into the net.sourceforge.playsudoku package, you'll find that the
contents of the puzzle are maintained in a multi-dimensional array called grid .
The Java declaration for this array is found in the SudokuGrid.java file and
looks like this:
private int[][] grid;
Unfortunately, JavaFX currently has no support for multi-dimensional arrays. So,
the first order of business is to convert grid into something JavaFX understands.
Listing 13.1 shows an additional Java method, called returnGridSequence() ,
Search WWH ::




Custom Search