| Project #1 (Tetris) | CMSC 132 |
| Due Date: Tuesday Feb 12, 6:00 pm | Object-Oriented Programming II |
| Type of Assignment: Closed | Spring 2008 |
This homework will give you experience working with two-dimensional arrays, and will give you an opportunity to start thinking about algorithm design.
You have to implement a class that provides an abstraction of a Tetris board, and you have to implement an AI logic module that calculates how good a particular board position is. You can implement a very simple AI logic that we describe for you, or you can devise your own logic. There will be a prize for the best AI logics.
We'll provide the rest of the code needed for the project, including the classes to represent Tetris pieces and handle all of the GUI display and interaction.
If you are not familiar with Tetris, the rules are as follows. Note that you do not have to implement all these rules. Most are implemented by the framework we supply. These rules are just for your game-playing pleasure.
This version of Tetris can be played either manually, or according to a provided AI logic. The AI logic plays a somewhat simplified version of the game; for each piece, it chooses an orientation and starting position, and then lets the piece drop straight down from there. This both hurts and helps the AI, compared to manual play. The AI can't move a piece to the left or right after dropping a distance, tucking the piece under an overhang. However, the AI doesn't have to worry about whether it can get a piece all the way over to the right or left from a center starting position.
You can play multiple games at once, using the same random sequence of pieces. This allows you to play in manual mode against an AI, or to play multiple AIs against one another, to see which logic wins.
There is also a lot of information and discussion about Tetris available. There is a lot of good information at http://colinfahey.com/tetris/tetris.html. There is a Slashdot poll on Tetris, asking people "What is their favorite Tetris piece". There are a bunch of interesting links and stories, including this interesting one including some background on Tetris, links to articles on NP-completeness results, and AI for Tetris.
You must implement two classes: tetris.Board and ai.TetrisAI1. The existing prototypes have method bodies that throw UnsupportedOperationException; those are just placeholders. You must implement all of the methods in those classes. Complete documentation describing the methods you have to implement can be found at javadoc. In order to play tetris execute the main method of the TetrisGame class.
Public tests can be found in the code distribution. You do not need to write student tests but you are encourage to.
Write a better version of computeMoveQuality() by defining a class named AI2 that takes into consideration the next piece that will be used. Feel free to design additional AIs.