15-112 Fall 2015 Homework 10 (the last!)
Due Sunday, 15-Nov, at 10pm
Read these instructions first!
-
This hw is entirely SOLO.
-
If you know what itertools are, don't use them to get around using recursion. If you don't know what itertools are, you may safely ignore this item.
-
None of this hw is autograded. Even so, you may make up to 5 submissions. As usual, only your last one counts.
-
Do not use global variables! Do use test functions! Do use helper functions!
-
You may use iteration (for + while loops), but only if you use recursion
meaningfully (except the decorator problem, where neither is required).
- solveRectangula(board) [50 pts]
Background: first, watch this short video on how to play
the game of Rectangula:
Now, your task is to write the function solveRectangula(board).
This function takes a board which is a 2d list of integers
corresponding to the board you see in the video, where blank
cells contain 0's. Your function should return a solution
to that board, which consists of a list of rectangles (in any
order) such that:
- Every rectangle in your solution is on the board.
- No two rectangles in your solution overlap.
- Every non-zero number on the board is inside exactly one rectangle in your solution, and the area of that rectangle matches the number.
- And every rectangle in your solution contains exactly one number on the board.
One oddity is that your rectangles must be of the form (row0, col0, width, height), where (row0, col0) marks the top-left of the
rectangle (remember, rows increase vertically, cols increase horizontally), and
width is the total number of columns, and height is the total number
of rows (so width*height is the area of the rectangle).
If there is no possible solution, your function should return None.
We have provided a lot of code for you. This code is in the file
hw10_rectangula_tester.py.
You should place that code next to your hw10.py file. Do not include any code from rectangula-tester.py in your hw10.py file! Instead, include these lines in your hw10.py file, below the #ignore_rest line:
###############################################
# ignore_rest
###############################################
# Place these imports in hw10.py below the ignore_rest line!
from hw10_rectangula_tester import testSolveRectangula
from hw10_rectangula_tester import playRectangula
testSolveRectangula(solveRectangula)
playRectangula(solveRectangula)
Then, when you run your hw10.py file, you'll run the testSolveRectangula function and the playRectangula function
in rectangula-tester.py.
Remember: Do not include any code from rectangula-tester.py in your hw10.py file!
Now, how should you solve a Rectangula puzzle? You may do this any way you wish, so long as you use backtracking meaningfully. That said, here are some hints about how we did this in our sample solution:
Have fun!!!
- OopyInvaders (with inheritance)
Write the OopyInvaders game described in this video:
In case it helps, here is the code at the end:
game1 = OopyInvaders()
game1.run()
print(game1.getFinalScore())
game2 = OopyInvaders()
game2.run()
print(game2.getFinalScore())
assert(OopyInvaders.totalGamesPlayed == 2)
Focus on the OOP parts, and make the UI just-good-enough to prove it works, as this is chiefly about OOP design and only partly about animations and UI. Enjoy!
- No bonus!
Note that there is no bonus on hw10. This is to leave you plenty
of time to study for midterm2 and to make some solid progress
on your term projects. We hope this helps!