Sudoku is a game which, in it’s current form, was invented in Japan, but has existed in other versions, for example, in French newspapers. I’ve attempted to recreate a game following the Japanese or modern version, and it’s surprisingly complex, in fact, Donald Knuth has invented an algorithm called ‘Algorithm X’, which is suited for solving Sudoku puzzles.
In this article I’ll explain the versions I’ve attempted to make for the JVM, using Swing, which uses imperative code for drawing, and another version with JavaFX, which uses both imperative and declarative code. In future articles, I’ll go into more detail regarding my experience with the two implementations, and provide the source code. I need more time to restore my files from a backup, and also to integrate an existing Sudoku puzzle solver, qqwing, which I discovered through GNOME’s Sudoku application: https://wiki.gnome.org/Apps/Sudoku/.
But first of all, why choose the JVM? Well, it’s because I wanted a new challenge, and a new perspective instead of Rust or C++, and because premature optimization is bad, and there are things that are much easier with JVM byte-code such as introspection, debugging, and other things like portability which C++ libraries can achieve, but they are tailored specifically to each platform and tool-set, whereas the JVM is the platform.
I don’t want to use .NET either, because the Java ecosystem has existed a lot longer, and has been possible to develop applications with user interfaces across desktop host operating systems, and because there are production applications that I’ve used written in Java, and undoubtedly, and because I’ve used components through the Android operating system on my phone.
My first version with Swing had a small learning curve as I was fairly new to many aspects involved, including Kotlin, Gradle and IntelliJ, but luckily the documentation is forthcoming, and found it fairly easy to draw graphics. The same was not true for the JavaFX version, and the drawing code was more complex as I used style sheet code to apply to the main Grid Layout component. Despite that, the JavaFX version draws more quickly, and the the view and controller code is separated nicely, which I imagine would be ideal for business applications.
That’s it for now, but watch this space till the next installment, when I’ve restored my backup.
Leave a Reply