GithubHelp home page GithubHelp logo

hoangchunghien / ai-sudoku Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 190 KB

Applying AI to solve Sudoku

Python 100.00%
sudoku-game game python3 artificial-intelligence constraint-propagation elimination-strategy

ai-sudoku's Introduction

Solving Sudoku Puzzle Game

Sudoku is one of the most popular puzzle games of all time. The goal of Sudoku is to fill a 9×9 grid with numbers so that each row, column and 3×3 section contain all of the digits between 1 and 9. As a logic puzzle, Sudoku is also an excellent brain game. If you play Sudoku daily, you will soon start to see improvements in your concentration and overall brain power.

In this project, I'll apply some AI algorithms to solve Sudoku game.

How to play a Sudoku Game

The goal of Sudoku is to fill in a 9×9 grid with digits so that each column, row, and 3×3 section contain the numbers between 1 to 9. At the beginning of the game, the 9×9 grid will have some of the squares filled in. Your job is to use logic to fill in the missing digits and complete the grid. Don’t forget, a move is incorrect if:

  • Any row contains more than one of the same number from 1 to 9
  • Any column contains more than one of the same number from 1 to 9
  • Any 3×3 grid contains more than one of the same number from 1 to 9

Install

  • You'll need Python 3.5 to run the code
  • You will need pygame to visualize the game board
  • Install all of the require packages
pip install -r requirements.txt

How to use the code

  • You must have a 9x9 grid of a sudoku game to solve, encode as a string with the length of 81.
grid = '2.............62....1....7...6..8...3...9...7...6..4...4....8....52.............3'
  • A number [1->9] represent the box value. A dot (.) represent the unsolve box.
  • Import code from solution.py
from solution import solve
from utils import display

result = solve(grid)
display(result)

2 6 7 |9 4 5 |3 8 1
8 5 3 |7 1 6 |2 4 9
4 9 1 |8 2 3 |5 7 6
------+------+------
5 7 6 |4 3 8 |1 9 2
3 8 4 |1 9 2 |6 5 7
1 2 9 |6 5 7 |4 3 8
------+------+------
6 4 2 |3 7 9 |8 1 5
9 3 5 |2 8 1 |7 6 4
7 1 8 |5 6 4 |9 2 3

Demo

python solution.py

ai-sudoku's People

Contributors

hoangchunghien avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

shivanshgoyal17

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.