Hw2 Tetris FAQs

Q: What do you guys grade on? Can I use really crummy style in my program?
A: No. We mostly grade by checking that your solution gets the right answer, but at times we will look at your source code -- checking for good OOP design or other style issues. For general programming style, we're not going to be super-strict, but your basic coding style should be decent -- reasonable variable and method names, reasonable use of decomposition to avoid code repetition.

Q: I'm trying to implement the brain player -- how do you call the brain from tick()?
A: First of all, the board needs to be in the committed state before calling brain.bestMove(). It's fine to call board.undo() first (notice that tick() calls board.undo() itself anyway). Then you can call bestMove() this way...

 move = brain.bestMove(board, currentPiece, board.getHeight()-TOP_SPACE, move);
The third argument is the height of the lower section of the board that is legal to play in -- the TOP_SPACE constant refers to the 4 rows up at the top where the pieces fall in. See the Brain interface for the full docs of how bestMove() works.

Q: When I run Tetris on UNIX, I get the following error messages:

Font specified in font.properties not found [-urw-itc
zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
.....
Font specified in font.properties not found [-urw-itc
zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
Warning: Cannot convert string "Escape,_Key_Cancel" to type VirtualBinding
Warning: Cannot convert string "Home,_Key_Begin" to type VirtualBinding
Warning: Cannot convert string "F1,_Key_Help" to type VirtualBinding
Warning: Cannot convert string "ShiftF10,_Key_Menu" to type VirtualBinding
Warning: Cannot convert string "F10,Shift_Key_Menu" to type VirtualBinding
Warning: Cannot convert string "KP_Enter,_Key_Execute" to type VirtualBinding
Warning: Cannot convert string "AltReturn,Alt_Key_KP_Enter" to type VirtualBinding

What is going on? What am I supposed to do?

A: We don't know exactly what causes them, but you can generally ignore error messages similar to those above. If you run your application on a different platform (e.g., Windows or MacOS), error message similar to those above won't appear. If you are running your application remotely (using something like VNC), and are encountering problems that don't appear when you run your code on other platforms, try going to Sweet Hall and running your code there. Any problems with your code are almost certainly not related to such error messages. If, however, you believe otherwise, feel free to visit office hours and talk to a TA.

Q: At the end of a game, with my brain turned on, the final piece lands at the top of the screen and continues to spin indefinitely. What's going on?
A: You probably forgot to handle the case where Brain.bestMove() returns null.

Q: I'm confused about undo. Does it just undo the last action on the board?
A: Undo takes you back to the previous committed board state. If undo is called after place(), it goes back to the state before place() was called. If undo is called after a place() and clearRows(), it goes back to the state before place() is called because the board isn't committed between a place() and a clearRows().

Q: What are we supposed to do if dropHeights gets passed an x that is outside the grid boundaries?
A: In general, you can assume that the inputs passed into dropHeights() are good.

Q: Why do filled rows turned green even before the piece has landed?
A: That's just how paintComponent was written. If you really don't like this behavior, go ahead and modify JTetris so that it checks that the piece has landed before changing the color.

Q: When I uncheck the Animate Fall mode, rows that get cleared don't turn green. Why?
A: It's probably because your code calls tick(DOWN) right after tick(DROP). tick(DROP) will draw the row green, but if tick(DOWN) is called immediately thereafter you won't see the green drawing.

Q: I have two HashSet's set1 and set2. Both sets have TPoints with the same x and y values, but when I call set1.equals(set2), it returns false. Why?
A: This is because TPoint overrides equals(), but not hashCode(). The default hashCode() method just returns the object's JVM memory location, so two different TPoint objects with the same x and y values will not have the same hash.

HashSet first uses hashCode() to determine whether two objects might be equal before actually calling equals() on them (this is what makes it efficient), so because the hashes are different, equals() is never called, and so HashSet thinks the elements are different. For this assignment you cannot add methods to TPoint, so you must use another way to compare the points