Project: Sudoku
Authors:
- Hugh Jackovich, Montana State University
- Lluc Cardoner, TU Wien
Purpose
Sudoku is a logic based number placement puzzle where a player must complete a 9x9 grid
where each row, column, and 3x3 subgrid (block) contains all digits 1-9 without any repeating elements.
Creating a Sudoku board will be challenging and will require use of the numpy module and possibly the random module.
This lab will use many of the features of numpy that you will start to feel familiar with
and will help solidify your confidence in using numpy for future programming endeavours.
Starting Material
It is recommended you use this Starting Template and that you follow further instructions given in the template.
Make sure you understand all of the given template and its use of the numpy module.
You may change any code given in the template to support yourself working through the TODO tasks.
References:
- It is recommended to utilize numpy.org for further help on intalling and getting started with numpy
- Installing numpy:
- Download the correct version of numpy from Here.
- Using CMD move to the directory of the file
- Windows: python -m pip install numpy
- Mac: pip3 install --user numpy
- Note: Some Windows users may have to use py instead of python
- For PyCharm users wishing to output colored text:
- Download the module Here
- Using CMD move to the directory of the file (likely downloads)
- Windows: python -m pip install filename
- Mac: pip3 install --user filename
- Note: Some Windows users may have to use py instead of python
- This documentation from scipy.org is a good reference to many of numpy's features
- Be sure to read up on creating an array, using numpy random, permutations, and retrieving columns and rows effectively
- Be familiar with multi-dimensional numpy arrays and how to slice them to get desired elements
Assignment
In this assignment you will create a Sudoku board game by first creating a valid solution.
You will ask the user for how many values to be removed from the board, you will then remove unique random positions on the Sudoku board that will then have to be
solved to finish the Sudoku game. You will continually prompt the user for a target (row,column)
and the value to be put into the given target. Your user prompts should not crash when given invalid inputs and should also be checked for validity on the board.
They should not be allowed to change starting positons that
were not removed. The user should also be able to print the solution board for help. When the board is solved, print the finished board and congradulate the user.
- Task 1 - Complete the new_block function so it returns a 3x3 block of randomly permutated values form 1 to 9 (included). Hint: look at numpy's basic functions.
- Task 2 - Fill in the rest of generate_game so that it produces a valid Sudoku solution. Hints are given in the template comments.
- Task 3 - Complete the check_input function so it returns false if the target is not a valid position in the board, if the choice number is not correct, and if the target is not a valid_target. Return True otherwise.
- Task 4 - Complete the is_finished function so it returns True if the solution and the puzzle board are the same. Return False otherwise. Hint: use numpy to compare the puzzle with the solution.
- Task 5 - Complete the print_game function so it prints the game board in a formatted manner.
- Task 6 - Complete the make_puzzle function so it creates the puzzle to be solved by replacing a specific number of unique elements with _ or 0 from the solution board . Keep track of the location (row,col) of the changed elements.
Here is an Example Output (uses 0 to replace) and a picture from PyCharm using colors here. Note: PyCharm can have different output font than Idle
Grading
Variable names should be appropriate and follow good naming convetions
- Your main() function tests for valid inputs by the user, and supports your usage of the functions and keeps a good program flow - [1 point]
- Task 1: Your new_block function successfully returns a random permutated 3x3 block from 1-9 - [1 point]
- Task 2: Your generate_game returns a valid Sudoku board - [3 points]
- Task 3: check_input works by checking if the user input is within the puzzle size, a valid target, and is not outside 1-9 range - [1 point]
- Task 4: Your program successfully detects a solved Sudoku board, prints the finished board, congradulates the user, and then ends - [1 point]
- Task 5: Your game is printed out in a easy to read formatted output - [1 point]
- Task 6: make_puzzle removes either a specified number by the user, or an amount equal to a difficulty level, store these locations in valid_targets, and replace them with _ or 0 - [1 points]
- Your code should be neat and have comments that are ample and informative. Remove any excessive redundant code with good use of functions and loops where possible - [1 point]
It is recommended to have a partner for this assignment, only one person from each group need to submit the necessary file with their partners name included. Code should be your own.