Friday, 28 October 2016

Revised Algorithm for Solution and Generation

 The algorithm I used for Solution generation worked by filling in each cell as it loops through the grid. Before filling a cell, it checks whether the numbers within its row and column are the same as the proposed number, and if it is it tries another. If it gets to the end of the list, then no number is suitable so it backtracks to the previous cells and checks whether it can swap the numbers.

Because in the case of Sudoku board generation random generation of numbers was paramount therefore I used random_shuffle . Help used was from :
https://bytes.com/topic/c/answers/578206-random-number-generator-use-random_shuffle
and
http://stackoverflow.com/questions/12540918/shuffle-vector-in-c/12541009

Even though the game winning condition does not work in my project by employing the above mentioned method I do not waste my memory into file reading of solved boards and then making my game board. I am able to generate infinite number of different boards without wasting any memory.

No comments:

Post a Comment