Giter Club home page Giter Club logo

sudoku-ai's Introduction

A simple Python3 based sudoku ai

AI uses constraint propagation to reduce problem size down to a solvable puzzle. For easy puzzles, this should be enough to solve the problem In the case that the problem is a more difficult puzzle, ai uses elimination and only one strategies to reduce problem size. Then AI recursivly calls itself, filling in random values in puzzle boxes not yet solved, until one call produces a solution

Constraint Propagation Strategies

Strategy 1: Elimination

If a box has a solved value, than none of its peers can have the same value. Peers are other boxes in the same row, column, or 3x3 grid. Elimination function goes through all these peers and removes discovered value from list of possible solutions.

Strategy 2: Only Choice

If there is only 1 box in a unit which would allow a certain value, than that box must be assined that digit. A unit is a boxes possible peers, ie boxes in same row, column, and 3x3 grid. Visually, this looks like: alt text

In example above, the only box that has 1 as a possible solution is the top right box. only_choice() discovers that, and puts 1 in top right box

Strategy 3: Recursive Search (When strats 1 & 2 looped fail to solve problem):

Called when a puzzle is more challenging and requires more work than repeated calls to strategies 1 and 2. Picks a box with a minimal number of possible values (box is either 1 or a 2). Trys to solve puzzle by creating new puzzle with pozzible values inserted, and recursivly calls main puzzle solving function (loop of strategy 1 and 2).

sudoku-ai's People

Contributors

seb-patron avatar

Stargazers

 avatar

Watchers

 avatar  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.