Skip to content

huggie1984/sudoku-canvas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sudoku
Canvas


An implementation of the popular puzzle game Sudoku.
The game is built with canvas using createJS libraries.
I Begun this project using a 2d array of numbers that represent a valid grid of numbers to populate a 9x9 grid.
var gridArrasy = [
    [{}, {}, {}, {}, {}, {}, {}, {}, {}],
    [{}, {}, {}, {}, {}, {}, {}, {}, {}],
    [{}, {}, {}, {}, {}, {}, {}, {}, {}],
    [{}, {}, {}, {}, {}, {}, {}, {}, {}],
    [{}, {}, {}, {}, {}, {}, {}, {}, {}],
    [{}, {}, {}, {}, {}, {}, {}, {}, {}],
    [{}, {}, {}, {}, {}, {}, {}, {}, {}],
    [{}, {}, {}, {}, {}, {}, {}, {}, {}],
    [{}, {}, {}, {}, {}, {}, {}, {}, {}],
    [{}, {}, {}, {}, {}, {}, {}, {}, {}]
];

Each object in the array would have the following format:

var gridObject = {row: 0, col: 0, grid: 0, value: 1};

Next step was checking if the solution the user entered was valid. The rules of sudoku a straight forward.
You cant repeat the same number in any horizontal, verticle or 3x3 grid so i created methods to check this logic.

Once the core of the puzzle was built I decided that I would explore the potential of randomly generating a valid 9x9 grid so each time you play you would be presented with a new puzzle.
This was not as straight forward as i though and after lots of trail and error I used my good friend Google.
After extensive research I decided to implement a backwards tracking algorithm.

With a full 9x9 grid with a valid solution all i now needed to do was remove x amount of values from the grid, the more numbers i remove the harder the puzzle will be.

Reference

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published