Git Product home page Git Product logo

sudoku-1's Introduction

Sudoku Solver as Firemonkey Cross-Platform Application

Introduction

This is a Delphi learning project prepared for Delphi 10.4 Sydney. This application is prepared to run on Windows 32/64, and on MacOS 64, and on Android and on iOS devices.

Thanks to the integrated half-solver, all 3 rules are continuously checked during input and only those digits are automatically available that do not cause rule conflicts.

Since December 2020, a full solver based on the backtracking algorithm has been added. It is used to explain the simplicity of this algorithm to the students.

Precondition

  1. You can start with the Community Edition of Delphi. See also https://www.embarcadero.com/products/delphi/starter/free-download

  2. You should be familiar with the rules of the math game sudoku. See also https://en.wikipedia.org/wiki/Sudoku

Getting started

  1. Clone this repo;
  2. Open the project Sudoku.dpr in the Delphi IDE;
  3. Press menu command Run in the Delphi IDE;

Start Form on Max

  1. Click in a number field (9) and select the first digit according to your first Sudoku example;
  2. Enter field by field until all of the predefined fields are filled out;
  3. Hint during entering the fields: For a simple Sudokus, the half-solver automatically fills all digits with the background color green as soon as only one digit can be selected;
  4. After filling in all the predefined fields, you can start to solve the Sudoku;
  5. Hint for solving: Begin with the smaller sets and choose a digit. Check the impact of your selected option in the matrix;
  6. In the case of a rule violation, you can use the undo button;
  7. The button Init let you start a new game;
  8. The button Save let you store the current matrix into a text file;
  9. With the button Load you can restore the former game stage.
  10. If the half solver makes your Sudokus too easy, dare to load the ExpertExample.txt.

Sudoku Example

Hint for field visualzation

  • (3..9): Number of selectable digits;
  • {Digit1, Digit2}: If only two digits can be selected, these are displayed directly as a set;
  • Field with border color red: Selected field in order to choose a digit;
  • Field with back color white: Entered digit;
  • Field with back color green: Calculated digit;
  • Filed with back color blue: Selected (tried) digit by the auto solver;
  • Field with back color pink: Role conflict in the horizontal line, the vertical line or within the 3x3 box.

Using the Auto Solver

Pressing the Solve button executes a single solver step.

The algorithm searches for the number field with the smallest variability starting from the upper left edge. I.e. it selects the number field that has only 2 possible digits or the number field with the smallest set of digits.

In the second step, the first available digit from this field is tentatively selected and checked if it does not trigger a rule violation in the half-solver. In case of a rule violation, the previous digit choice must be reversed. This digit must not be tried again in a next solver step.

Sudoku Example while auto solving

The Auto Solve button can be used to automatically repeat the solving steps until a final Suduko configuration is reached. Thereby the solving speed can be selected. A log informs about each solver step.

Have fun solving Sudokus and understanding the backtracking algorithm.

sudoku-1's People

Contributors

arcanaceus avatar christophschneidertrihow avatar schneiderinfosystems avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.