Home > Web Site Updates > SudokuSolver v1.0

SudokuSolver v1.0

November 3, 2013

Just to let everyone know that v1.0 of SudokoSolver has been released. This is a set of C++ classes which implements support for the classic 9*9 Sudoku puzzle as well as a simple MFC Dialog based app which generates and solves Sudoku puzzles.

Features

  • Provides a simple C++ Header only module and class to represent a Sudoku grid. The class in this header is called CSudokuGrid and provides most of the reusable functionality.
  • The sample app provides a simple VC 2013 dialog based Sudoku puzzle generator and solver. If you click the "Generate" button in the sample app, it will generate a solvable puzzle with the specified number of cells left empty (as taken from the empty cells edit box). The algorithm to generate a puzzle is based on the information from http://blog.forret.com/2006/08/a-sudoku-challenge-generator/.
  • The solving code demonstrates how to integrate MFC multithreading into a algorithm in a manner such that it is cancellable and provides UI feedback while running without the need to provide a blocking modal dialog UI. The logic for this is spread across the Solve, _WorkerThread, WorkerThread, OnThreadFinished, OnThreadStatusUpdate, StopWorkerThread and OnBnClickedSolve methods of the CSudokuSolverDlg class. The solving code is based on a subset of the information from http://norvig.com/sudoku.html.
  • As the solving code runs it will set the background colour of the cell which it is operating on in red and indicate the depth of the algorithm using "[]" in the cell. The code to do this is executing from a worker thread but to update the UI the main thread must do the actual work. To avoid overloading the main thread with update requests, the worker thread implements logic to only update the UI every 100 ms. To review this code, please take a look at the CSudokuSolverDlg::Solve method.
  • When the solving code finds a solution it will set the background colour of any updated cells to green.
  • The background colouring of the edit boxes is done with a very simple CColorEdit MFC class which is derived from the standard CEdit control class. This class demonstrates how to implement background colors in an edit box using MFC using the standard WM_CTLCOLOR message handling mechanism.
  • Please note that as the solving algorithm is currently implemented it will not guarantee that there is only one solution to the provided puzzle and instead will just pick the first solution found.
Categories: Web Site Updates
  1. February 24, 2014 at 11:24 am

    Hi, just wanted to say, I enjoyed this blog post. It was funny.
    Keep on posting!

    • March 1, 2014 at 7:56 pm

      Not sure how writing some code to solve a Soduku puzzle could be classed as “Funny”, but whatever floats your boat

  1. No trackbacks yet.
Comments are closed.
%d bloggers like this: