CMU 15-112 Spring 2017: Fundamentals of Programming and Computer Science
Homework 5 (Due Sunday, 19-Feb, at 8pm)




  1. Friday optional OH [0 pts]
    Just this week, in place of our usual Friday recitation, we will have optional all-day OH on Friday, from 10am to 10pm. What a great chance to get some extra help on this hw!

  2. bestQuiz [30 pts] [autograded]
    Do bestQuiz from here.

  3. isKingsTour [30 pts] [autograded]
    Do isKingsTour from here (see #2).

  4. playGame42 [40 pts] [manually graded]
    Below an "#ignore_rest" line, write the function playGame42(rows, cols) that takes the dimensions of a board and displays a game of "42" in a suitably-sized window containing a board of those dimensions. The game of 42, invented here (and not especially enthralling), works as such:
    1. The board starts empty.
    2. Two players (one blue, the other orange) take turns moving. The UI should always make clear whose turn it is.
    3. The only event that is used is keyPressed. Your mousePressed and timerFired functions should simply pass, as in the starter code.
    4. At any time, a single cell in the board is highlighted. The current 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. If the current selection is empty, that digit is displayed in the currently selected cell, using the current player's color. Otherwise, if the current selection is not empty, the current player loses that round.
    6. When a digit is placed, the players "turn sum" is the sum of all the digits neighboring that digit, plus the digit itself. If the "turn sum" equals 42, the player wins that round! Otherwise, play continues with the other player's turn.
    7. If the board is full and no more moves remain, then the player with the turn sum in that round that was closest to 42 wins that round. If there is a tie, the round is a draw and each player wins 1 point for the round.
    8. At the end of each round, the score is updated, and the board is cleared and the next round begins.
    9. A score should be displayed, 1 point per round, first to 5 wins the game.
    10. When the game is over, the message "Game Over" should be displayed, and the score should make it clear which player won, and all further keypresses should be ignored.
    Note: so long as you follow the rules above, there are many tiny details left unanswered here (how large should the board be? where does the score go? what font for the score? 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: 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 window
    3. Display the grid
    4. Highlight a cell
    5. Hardcoded cell values
    6. Display moves
    7. Take turns
    8. Wint rounds with 'r'
    9. Win rounds with 42
    10. Rounds with full board
    11. Win game
    12. Odds'n'ends

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

  6. Bonus/Optional: enhancedOthello [2 pts] [manually graded]
    Do enhancedOthello from here (see #6).

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

  8. 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!

  9. 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!