Home
Important Dates Grading Lectures Optional Readings
Exercises Group Assignments Individual Assignments
Exam Schedule
Videos Slides
College of Engineering Aeronautics and Astronautics Agricultural and Biological Engineering Biomedical Engineering Chemical Engineering Civil Engineering Construction Engineering and Management Electrical and Computer Engineering Engineering Education Engineering Professional Education Environmental and Ecological Engineering Industrial Engineering Materials Engineering Mechanical Engineering Nuclear Engineering
EPICS (Engineering Projects In Community Service) First-Year Engineering Program First-Year Engineering Honors Program Global Engineering Program Minority Engineering Program Professional Practice (Co-Op) Program Women in Engineering Program
College Administration Schools Programs All Groups All People ECN Webmail
Purdue Home

ECE 462 Group Assignment

Stage 3: Two-Player Tetris Game

Deadline: 11:59PM 2009/11/13

Requirements

In this stage, the three main tasks are to:

  • Extend the single-player Tetris game to two-player games (human vs human, human vs computer), transferring eliminated lines in one playfield to its opponent's playfield. This should be a good opportunity to use objects: the two games are simply two instantiation of game class.
  • Implement networking functionality, allowing your Tetris game to connect to a server and play against another client that is connected to the same server. This helps you appreciate how details are hidden by using the network classes provided by Java or Qt. Please finish Exercise 9 before you start this part.
  • Design a more effective algorithm to rotate and place pieces

In this stage, you need to design an algorithm to automatically rotate and place pieces. Five sequences are given to you; each sequence contains 20,000 pieces. Your program must be able to eliminate at least 100 lines in one of the given sequences.  You are allowed to analyze these sequences for designing your algorithm. However, your algorithm must not have any knowledge beyond the immediate next piece.  In other words, your algorithm must be "on-line" reacting to new pieces without knowing them in advance. This is essential because in stage 4, your program has no knowledge about future.

Sample sequences: sequence1 sequence2 sequence3 sequence4 sequence5 (in ascending order by difficulty)

Game Components

  • Two playfields: the main window now contains two identical playfields instead of one.  In a single-player game, the right playfield is simply not used; in other modes where two players are involved, each playfield is controlled by one player.
  • Menu items: The following more items are also required in this stage, some of which are already included in Stage2
    • Single-player mode: Switch the game to single-player mode, where only the left playfield is used.  A local player plays the game with keyboard.  Eliminated lines are not transferred.
    • Human vs Human mode: In this mode, two playfields are used.  Each playfield belongs to one human player.  Both players play with the same keyboard, but using different sets of keys.  Eliminated lines are transferred according to the rule (stated below).
    • Human vs Computer mode: In this mode, the left playfield belongs to the human player, and the right playfield is automatically controlled by a computer player.  Eliminated lines are also transferred.
    • Netplay mode: In this mode, the left playfield belongs to the local human player (using keyboard) and the right playfield is controlled by a remote player on the network.  See Networking Protocol for details. In this case, a player does not need to know whether the opponent is a computer or a person.
    • Qualifier mode: In this mode, your program connects to the server and specify "GAMETYPE=tetris-qualifier" as your game type.  It will then enter a network-based single-player game to test the efficiency of your algorithm.  This mode is used to grade your program on algorithm.
    • Configure keys: show a dialog box that allows user to assign keys for two players (because two human players are involved in the Human vs Human mode).
  • Score labels: A label is attached to each playfield, displaying the total number of eliminated lines in that playfield.

Rules for Local Games

  • Unlike the original version of Tetris game, rotation is allowed as long as the destination accommodates the piece:
    rotation allowed from collision to collision

  • When a horizontal line is full, it is eliminated and the score is updated correctly.
  • When elimination occurs, squares above the eliminated lines fall down due to gravity. The effect of gravity is illustrated as below:
    Common Tetris Gravity
  • In two-player games, the eliminated squares, except the most recently added, are moved to the opponent's field at the bottom after the opponent drops(fixes) the current piece.  An example is shown below.  If the transferred line is eliminated for the second time, the lines will not be tranferred back but simply vanish from both playfields (otherwise quick death is unavoidable).

    becomes

Rules for Online Game (Important Documentation)

Please read the documentation GPA Specification for Stage 3 carefully.  This additional documentation specifies a large set of rules that are required to follow for networking.

Another reference is Network Protocol for Online Super Tetris (slides).  This is the slided of the presentation on 10/9, which gives an outline of the network protocol specification, but lacking in some necessary details.

If there is any conflict between these two documentation, please refer to the first documentation (not the slides).  IYou are also encouraged to post such inconsistency on Blackboard to remind other students as well as the TA.

Grading

Functionality (5pt)

  • (Prerequisite 0pt) Your program functions as a local single player Tetris game (this is what you should have accomplished in Stage 2).  If your program does not meet this prerequisite, it will not be graded at all.  The prerequisite is considered fulfilled if the single-player mode is evaluated no less than 3.6 points out of 4.8 using the grading rules for "Program Functionality" in Stage 2.
  • (1pt) Two-player game: In two-player game mode, the player can choose to play against another human player or agaist a computer player locally (without networking).  The action keys for the second human player can be assigned in the "Configure Key" dialog (in Stage 2).
  • (0.6pt) Transferring eliminated lines: In a local two-player game, if one player manages to eliminate one or more lines, each of the eliminated lines is transferred to the bottom of the opponent's playfield, unless such a line was originally transferred from the opponent (and hence it will not be transferred "back" to avoid infinite cycle).
  • (0.4pt) Establishing connection: After asking user to provide the address and port number, your program can connect to the server and do the basic connection establishment (send ID, GAMETYPE and READY messages).
  • (1pt) Receiving actions: Your program responds correctly to the message received from server side.
    • 0.4 point for receiving LEFT,RIGHT,ROTATE and FALL and process them correctly
    • 0.2 point for receiving PIECE and process it correctly
    • 0.2 point for receiving ATTACK and process it correctly
    • 0.2 point for receiving GAMEOVER, WIN, LOSE and process them correctly (show a text message upon receiving WIN or LOST)
  • (0.6pt) Synchronization: The playgrounds (player's and opponent's) are always synchronized with server side.  Please note that in some situation, the server may reject an action proposed by the client.
  • (1.4pt) Quality of your algorithm: You can receive up to 1.4 points based on the quality of the algorithm. The quality is determined based on the highest score among the five given sequences.
    • 0.2 point if your program can eliminate 20 or fewer lines
    • 0.5 point if your program can eliminate 21 to 50 lines
    • 0.9 point if your program can eliminate 51 to 99 lines
    • 1.4 point if your program can eliminate 100 or more lines
    • Note: your program must be able to send "GAMETYPE=tetris-qualifier" in order to get graded in this category.
  • (Penalty -2pt) "Sudden death": If the main window suddenly disappears, or the program stopped functioning unexpectedly, without telling user what has happened, 2 points will be taken.
    • Your program should always continue when an exception is encountered. No matter what happens, your program must not crash (fatal exception or segmentation fault, for example).

Architecture (0.5pt)

  • (0.3pt) Polymorphism: use polymorphism to handle local and network games together.  Justify your usage of polymorphism.  (There are many correct designs to this requirement; adopt your own analysis)
  • (0.2pt) Encapsulation: public members (functions, fields, etc.) should be public only when they cannot be assigned with lower access (protected or private).  For example, if you declare a public field but it is never used outside the class, the class is considered not well-encapsulated and you may receive consequent penalty.

Program Readability (0.5pt)

  • (0.2pt) Abide by the code style rules specified in both Stage 1 and 2.
  • (0.3pt) Write a concise documentation about
    • how you handle the incoming network messages, particularly specifying 1) the library classes in Java or Qt that you used to handle networking 2) whether the communication is Blocking or Non-blocking)
    • the design of your algorithm for the Demo mode.  Elaborate the strategy used by the computer player.

Note: Please submit a peer evaluation form along with your project in Blackboard.

Bonus Points

These bonus points are added above the 10 participation points. Therefore, they are great opportunities to improve your grades.

  • (0.5pt) SE (sound effect): When a piece cannot move down any more, a sound effect should indicate that. When a line is eliminated, another sound effect is used. If multiple lines are eliminated at once, yet another sound effect is used.
  • (0.5pt) Demo video: If you post a demonstration video (at least one minute long) with sound on-line (such as Youtube) and include the URL in your submission.
  • (1pt) Applet: Make your game an Applet. A human player can play along or against a computer.  (note: Applet functionality is only available using Java)
  • (1.5pt) Excellent algorithm: You probably want to have an "accelerated mode" for testing your program because it will take a while to eliminate so many lines. To receive this bonus, please explain which sequence you use and the number of lines eliminated.
    • 0.5 points if your program can eliminate 500 to 999 lines
    • 1.0 points if your program can eliminate 1000 to 1999 lines
    • 1.5 points if your program can eliminate 2000 or more lines 

Permission to Use Your Code

Do you allow  the instructor to use your code for research and education purposes?  The instructor may use your code for teaching, research, and publication. This is a non-exclusive permission to the instructor. The instructor does not "own" your code and you can still use your code, for example, to build a commercial product.  If you do not give the instructor this permission, please conctact the instructor before December 15, 2009.