CMU 15-112 Fall 2016: Fundamentals of Programming and Computer Science
Homework 5 (Due Saturday 1-Oct, at 8pm)
- This hw is SOLO. See the syllabus for details.
- Starter files: Create your own hw5.py (based on lab5.py). Here is cs112_f16_wk5.py
- This week you may use up to 6 submissions. Only your last submission counts.
- Do not use recursion this week.
- Do not hardcode the test cases in your solutions.
This week only, you may use one Late Day at a 10-point deduction. If you submit 1 day late, autolab will first use a Grace Day at no penalty. If you submit 2 days late, autolab will use both a Grace Day and a Late Day at a 10-point deduction. Deadlines are always 8pm every day.
- Be sure to place your graphics code, including the import tkinter line, below the #ignore_rest line, as it already is in the starter file. Otherwise, the autograder will crash on the import line and you will score 0 on that submission.
- For animations, be sure to adapt the code from events-example0.py.
As usual, there is no Late Day this week.
- Friday optional OH [0 pts]
Same as last week. Attendance is optional, and you can stop by for any or all recitations, which run from 9:30am to 5:30pm all day! - bestQuiz [30 pts] [autograded]
Do bestQuiz from here. - isKingsTour [30 pts] [autograded]
Do isKingsTour from here (see #2). - 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:- The board starts empty.
- Two players (one blue, the other orange) take turns moving. The UI should always make clear whose turn it is.
- The only event that is used is keyPressed. Your mousePressed and timerFired functions should simply pass, as in the starter code.
- 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).
- 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.
- 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.
- 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.
- At the end of each round, the score is updated, and the board is cleared and the next round begins.
- A score should be displayed, 1 point per round, first to 5 wins the game.
- 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.
- Bonus/Optional: runOthello [1 pt] [manually graded]
Do runOthello from here (see #4). - Bonus/Optional: enhancedOthello [2 pts] [manually graded]
Do enhancedOthello from here (see #6). - Bonus/Optional: runFancyWheels [1 pt] [manually graded]
Do runFancyWheels from here (see #5). - 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! - 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!