CMU 15-112 Spring 2017: Fundamentals of Programming and Computer Science
Homework 5 (Due Sunday, 19-Feb, at 8pm)
- This hw is SOLO. See the syllabus for details.
- Note: no starter files this week. Be sure to use the linter,
and include test cases for the non-graphics/non-animation functions.
- For animations, be sure to adapt the code from
events-example0.py.
- When you are ready, submit hw5.py to autolab. For this hw, you may submit up to 6 times, but only your last submission counts.
- Do not use recursion this week.
- Do not hardcode the test cases in your solutions.
- Be sure to place your solution to all graphics code, and all its helper functions and the tk import, below the #ignore_rest line, so the autograder is not confused by it.
- 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!
- 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.
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!
- Read the problem
- Display the window
- Display the grid
- Highlight a cell
- Hardcoded cell values
- Display moves
- Take turns
- Wint rounds with 'r'
- Win rounds with 42
- Rounds with full board
- Win game
- Odds'n'ends
- 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!