Sudoku

Programming provides exercise for your brain. Sudoku is also said to provide exercise for your brain. We are going to combine programming and Sudoku for some serious brain exercise. This is a large assignment so I have broken it up into three difficulties: easy, medium and hard. Depending on how much exercise you can handle you should pick a difficulty and stick to it.

If you don't know how to play Sudoku, here are a few good tutorials:

Choose the following video that corresponds to the degree of difficulty you are willing to take on:

Setup

Fork the following repository and clone your copy.

Sudoku

Open sudoku-easy.py, sudoku-medium.py, or sudoku-hard.py, based on your preference, in your text editor.

I have provided a module, sudoku_helper that provides a lot of functionality. A list of functions is provided in the Tips section.

Requirements

  • continue to print a menu that allows a user to play a new game, see scores or

    quit until an option is selected

  • when playing a game, print the Sudoku board and accept and parse the users

    input to alter the board. Use whatever format you wish to indicate rows,

    columns and values

  • loop until the user has won or quit

  • keep track of wins and losses per user in a file (losses happen when they

    quit)

  • use functions to create logical separations in your code. This will increase

    readability and maintainability

Tips

Sudoku Helper

print_board(board) takes a 2D list and prints it to the screen in a nice way with borders that looks like a Sudoku board.

get_boards() returns the list of boards from sudoku-boards.txt. Each board is a 2D list that contains the numbers for each position on the board.

get_ch(message=None) prints out an optional message and reads the user's input after a single character has been entered.

detect_win(board) determines if the given board is in a winning configuration. That is if all of the rows contain 1-9, all of the columns contain 1-9 and all of the squares contain 1-9.

update_board(board, col, row, val) takes the board and the column and row that the user entered along with the value they wish to update at the given location. It returns the new board or None if an update was not possible.

print_sudoku() prints Sudoku in pretty ASCII art letters.

print_victory() prints Victory! in pretty ASCII art letters.

Use All of the Boards

To use all of the boards open the sudoku-boards.txt file and remove the first # comment character from beginning of all of the lines in the file after the test board. I have annotated each board with how easy it is so you can choose to only uncomment the easy ones at first if you are trying to learn sudoku. You may also want to comment out the test board so that doesn't get included while you are playing for real.

Last updated