8/8/2023 0 Comments Mini sudoku generator![]() This project over all was a complete success because we were able to create a fully functional sudoku game that is capable of generating unique sudoku boards and being able to solve the game so as to notify the user if their input was correct. In order for the user to play another game they must call python Sudoku.py again from the terminal. Once the board is solved, the program prints a message notifying the user, and then the program terminates. This portion of the code was placed inside of a while loop to continuously print the puzzle and ask for input until the board was solved. We also made checks to issue error messages if the user placed a number that would not lead to the solution, or if they tried to input a number in a spot that was already filled. We then implemented checks to make sure that the inputs were in the range of 1 to 9, and issued error messages if they were not. This step was completed by using the input function in python to ask the user for a row, column, and value. This step was fairly simple, as all we had to do was print the 9x9 array that is the puzzle and then take and check input from the user. The last step was then to create the gameplay portion of the project. We then saved the most recent puzzle that generated a unique solution by saving the previous generated puzzle to a variable called PrevBoard, which concluded the generation of the initial board. We put this process into a while loop so that it would continuously take out numbers from the puzzle until the solution to the puzzle was not unique. We then added a constraint to the solver saying that the solution must contain the numbers that are in the board returned by reduceSudoku(Board). This function randomly selects a position in the 9x9 array and replaces the number in that position with zero. We started this by using a function called reduceSudoku(Board). We randomized the generation of the board by blocking the solution of the solver a random amount of times so that the board generated would not be the same every time the code is run.Īfter generating the puzzle as a 9x9 array, we developed a method to take out numbers from the puzzle so that the board would not be fully filled out. ![]() With these constraints, we passed the solver to a function called generateSudoku(s) that converts the values of the solver model into a 9x9 array of integers, and returns that array. This filled in board was generated by creating a solver with constraints that tell the solver that there should be 81 numbers, the numbers in rows / columns / subsections should be distinct, and the values of the numbers should be between 1 and 9 inclusive. For the generation of the puzzle, we also decided that the best method would be to use a z3 sat solver to create a filled in board. ![]() We were able to achieve all of these goals as we did create a fully functional sudoku game that is able to check a user's work and is capable of generating a unique sudoku board everytime the program is run.įor the actual coding of our Sudoku project, we decided that we should create several functions that would handle generation of the Sudoku puzzle and several functions that would handle the user interface / gameplay portion of our project. Our goals in this project was to create a fully functioning sudoku game that creates unique games every time and will be able to tell if a given input is correct or if it will make the rest of the game unsolvable and that it will notify the user if they pick an incorrect value for a given row and column. In addition to wanting to make a fun interactive project we also played sudoku before this project and wanted to create our own sudoku games that we can play. The motivation behind creating this sudoku game was that we wanted to create an interactive project that a user could have fun with, and the best option to accommodate these conditions was sudoku. The Solver was also necessary to check whether or not an entered number was correct or not. ![]() To accomplish this we also needed to create a sudoku solver so that we could check the board we were generating to make sure it was solvable and that it only had one solution, or in other words that it had a unique solution. The scope of the project was to create a sudoku game in python that can be played within the terminal. In-Depth Explanation of Project and Methods ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |