16 January 2022
This is the component responsible for using other components like Extractor, Recognizer, Solver and Plotter. It glues these components together to create a pipe responsible for the entire process of solving the puzzle from an image.
The Engine can use extra params, they are:
solutionColor: the color of solution numbers found by the Solver;
recognizedColor: the color of numbers recognized the the Recognizer;
debug (default false): if true, the engine will generate a solution with images from the intermediate steps. Case false, only the image from the final step will be generated.
The Engine also uses some fallback mechanism in case a problem occurs, it simply returns the original (unsolved puzzle) image.
The following diagram shows how the Engine ensambles other components in order to generate a final solution.
The code for the Engine can found be found on sudoscan-api sub module, on a class called SudokuEngine
.
Sudoscan comes with a command line application. The cli application can be downloaded on this link.
The cli application was built using picocli and micronaut to warp a SudokuEngine and expose its functionalities through a command line interface. Picocli is an awesome library that allows creating rich command line applications for the JVM. Micronaut is used to enrich the application with auto-generated bean injections, auto-configuration and such.
A Sudoscan cli application can only have a single implementation for Solver and Recognizer. Since Sudoscan comes with different implementations for both components, a different implementation can be used at build time.
For instance, the following command (executed on the project’s root) generates a final jar with ojalgo solver and djl recognizer:
gradle -Pojalgo -Pdjl clean assembleCliApp
To generate a version with choco solver and dl4j recognizer, no extra parameters need to be defined (since they’re the default components). The following command must be executed:
gradle clean assembleCliApp
The code for the cli application can found be found on sudoscan-cli.
Micronaut applications can be ahead-of-time compiled to a GraalVM native image, with extremely fast startup time and lower memory requirements, which can be distributed as a single executable file.
The latest GraalVM version tested was GraalVM CE 21.2.0 (graalvm-21.2.0+java11) which is for Java 11. To build the native image, run the following command on sudoscan-cli module:
gradle -PjavacppPlatform=linux-x86_64 clean nativeCompile
Another honorable mention related to Sudoscan is the sudoscan-web project. This is a web version of the Sudoscan Cli (also built with micronaut).
A quick way to see it in action is to use its docker image build. Just run the following command:
docker run -p 8080:8080 pintowar/sudoscan-web
More information about it can be found on it’s README file.