CMU 15-112 Fall 2017: Fundamentals of Programming and Computer Science
Homework 5 (Due Saturday, 30-Sep, at 8pm)

  1. playSudoku [100 pts] [manually graded]
    Write the function playSudoko(board) that takes a valid Sudoku board and displays an interactive game allowing the user to play Sudoku.

    Here are some things to consider while building your game.
    1. The board is stored as a 2D list using the format specified in lab5.
    2. The game starts by displaying the full 9x9 grid (in the format of a standard Sudoku board) and filling in the numbers already included.
    3. The only event that is used is keyPressed. You will not need to make use of the mouse or a timer.
    4. At any time, a single cell in the board is highlighted. The player can change the highlighted cell with the up, down, left, and right arrows (with wraparound, so for example, pressing the left arrow with the selection in the leftmost column causes the selection to move to the rightmost column in the same row).
    5. To make a move, the current player can press a single digit key to insert a number into an empty square. The move is only allowed if it will still result in a valid board.
    6. A player can clear the number from a square by pressing the backspace key.
    7. Initial numbers (squares that were filled in before game play began) should be a different color than numbers added by a player. In addition, a player cannot modify initial numbers.
    8. If, after a move, the player has properly filled in the entire board and won the game, then a message should be displayed congratulating the player. After this, all further keypresses should be ignored.
    9. You will want to make use of your sudoku related code from lab5. In order to facilitate this, you are going to create your very first Python library module. You should place your functions inside the library that we have included. Once your code is in the sudoko library, you can just call the functions directly from within (This is due to the way we import them at the top of When grading, we will provide our own version of the library that contains our implementation of the library. Do not include any of your lab5 code inside, you must put it into
    10. If you did not finish lab5 properly, don't panic! You can build the vast majority of the game without a functional library. You simply assume that all moves are valid and that any full board is a winner. There will be a point penalty for this, but the majority of the points will be for the rest of the game.
    Note: So long as you follow the rules above, there are many tiny details left unanswered here (how large should the board be? what colors should I use? exactly what should the board look like? what font for the numbers? etc, etc, etc). You have to decide them for yourself. Do not ask on piazza, do not ask at OH. Just decide. Keep it simple. We are not looking for anything amazing here, just a simple playable game that follows the rules above. Have fun!

    Addendum: If you want to test whether you can win the game properly, but don't want to play lots of Sudoku, consider testing with an almost complete board such as this one:

  2. Addendum 2: You may solve this problem any way you wish. That said, here are some hints/suggestions for one approach to solving the problem. Use this or not as you wish. Good luck!

    1. Read the problem
    2. Display the board
    3. Improve the board display
    4. Highlight a cell
    5. Show initial numbers
    6. Handle moves
    7. Win the game

  3. Bonus/Optional: runFancyWheels [1 pt] [manually graded]
    Do runFancyWheels from here (see #5).

  4. Bonus/Optional: playSokoban [3 pts] [manually graded]
    First, read the Wikipedia page on Sokoban. Then, write the function playSokoban() that plays the game. Do not use any images. All drawing must be with graphics primitives (lines, rectangles, ovals, etc). Also, do not use any sound. Besides that, design as you will. The nicer the game, the more points awarded. Have fun!

  5. Bonus/Optional: runDotsAndBoxes [3 pts] [manually graded]
    First, read the Wikipedia page on Dots and Boxes. . Then, write the function runDotsAndBoxes(rows, cols, maxSecondsPerTurn) which will play a human-human Dots and Boxes game on a rows x cols board, but also not allowing more than maxSecondsPerTurn time to elapse on any give turn. If the time elapses, the screen should visibly flash and the player should lose that turn (though not the game). Your user interface can be simple, even quite plain, but it must be functional so two people can use it to play. It must display the board, make clear whose turn it is and where legal moves are, make it easy for players to enter moves, actually make those moves if legal (or reject them if illegal), display who has captured which boxes, alternate turns, display the score, detect game over, and print a suitable game over message. Don't forget about the maximum time per turn, too!