15-112 Spring 2013 Homework
6
Due Tuesday, 26-Feb, at 9pm
+5-point Early-Bird Bonus if submitted by Monday, 25-Feb, at 9pm
Read these instructions first!
- This hw is SOLO, even
more so than as explained in the syllabus. For this hw, you may not work
with anyone else in any way, which means you may not discuss these problems
with anyone else, even if you do not show them your code nor view theirs.
Except, of course, you may always discuss the problems with the course
staff, who are happy to help!
- The same rules as hw5 apply.
- Submit a single file, hw6.py, containing all your solutions, with your
manual solutions in a triple-quote string at the top.
Remember to place any test functions you might have, or
any top-level code (that runs when the file is loaded), below the #ignore_rest
line so the autograder does not run it.
- [25pts] Do the following problems from
f12
hw5a:
- solvesCryptarithm
- bestScrabbleScore
- [25 pts; 4 pts each + 1 free pt] Do any 6 problems of your choosing from
f12
hw5b. These are SOLO, not collaborative, despite what f12 hw5b may say.
The problems you elect not to do still make for excellent study problems for
upcoming quizzes and exams. As usual, place your solutions in a
triple-quoted string at the top of your hw6.py file, and be sure to show
your work!
- [25 pts] Othello
- Find an online Othello game and play
it for a while, until you are comfortable with the rules.
- Study the
othello.py code from the case study we covered in class. You should
study it thoroughly since both wordSearch and Othello are now likely to
appear on upcoming quizzes and exams (and not just appear, but perhaps
play a central role).
- [4 pts each + 1 free pt] Make the following changes to the
code. Except as noted for printBoard, do not change the names of any functions, nor the names or number
of parameters those functions take. Otherwise, the autograder will not
work!
- Fix getMove so that it works properly up to
a 26x26 board. Right now, it fails if there are more than 9 rows.
- Add the function getLegalMoves that takes a
board and a player and returns a list of all the legal moves for
that player as a list of (row,col) tuples, sorted first by row and
then (for the same row) by column. If there are no legal moves for
that player, return the empty list.
- Change printBoard to display legal moves as
a dot (.) rather than a dash (-). To do this, you should
add an additional parameter to printBoard, so it takes both a board
and the currentPlayer.
- Change the game (again, without changing
any function names or parameter lists) so that it works with
wraparound, so for example, if you head off the board on the right
edge, you re-enter on the left edge. Wraparound must work across all
4 edges (left, right, top, bottom), and then in all 8 directions.
- Modify playOthello so that it displays the
current score as the game is played (the score for each player is
the total number of pieces that player has on the board at that
time).
- Add the function
playOthelloAgainstRandomComputer(rows, cols), that works just like
the just-modified playOthello, only player O is the computer, which
makes random moves from among the legal moves available to it.
- [25 pts] The Memory Game
In this game, an RxC rectangular grid is filled with random numbers such
that each integer from 1 to RC/2 occurs exactly twice. Numbers are hidden.
On each turn, the player uncovers two numbers. If they match, they are
unhidden (so the player can see them). Play ends when all the numbers are
unhidden. The score depends both on the number of incorrect guesses and the
total time required. Write the function playMemoryGame(rows, cols) that
implements this game as described. Follow this spec when you can, but there
are also a lot of decisions left up to you. In any case, make your game
reasonably attractive and playable, though we understand that console-based
games have their limitations. Also, include a help command that explains
how to enter commands.
Note: we will only test this up to 26x26 grids (so you don't have to deal
with column AA...).
carpe diem - carpe
diem - carpe diem - carpe diem - carpe diem - carpe diem -
carpe diem - carpe diem - carpe diem