Posted: March 12th, 2023
Java programming need to develop game Play Tetris
Due Date: March 3
Need full solution: Problem Coverage 100% and 100% code path test coverage
Please feel free to improve and resubmit your code as many times as you like (before the deadline) in order to improve your score.
Overview
TetrisLinks to an external site.
was arguably the most popular single-player computer game of all time by the early 1990’s. It’s incredibly easy to learn, and even to this day it’s widely considered to be among the best video games of all time.
There are some animations in the link above, but in case you’ve never seen it, the interface consists of a tall narrow rectangular grid as the game board. Randomly-selected geometric shapes appear at the top, one at a time, and begin to incrementally fall from top to bottom. The player must manipulate each shape as it falls, by moving it horizontally within the board and/or rotating it in 90° increments. Once the shape can fall no further, it becomes locked in place, taking up some of the available spaces within the board.
The goal is to continue playing as long as possible, so the player must attempt to place the shapes strategically. Completing horizontal rows is crucial to prolonging the game. If the player can form one or more horizontal rows completely full of blocks, those rows are removed, with all blocks above falling downward. Eventually, the board fills upward to a limit line, and if any portion of a shape is locked in place above this line, the game is over.
You’ll see all of this in action soon enough, and it’s usually quite easy to understand once you’ve played it for just a few minutes.
Requirements
Building a full-functional Tetris application requires a little more Java than what we’ve covered yet, so you’ll be provided a working application that you can download and play. It’s a simplified version of the game, with a very rudimentary scoring mechanism, but it’s still quite enjoyable and challenging.
You may wonder, if the application is provided, what this is assignment all about. The goal here is to develop a simple Artificial Intelligence (“AI”) system, capable of
playing the game as if it were the human player. The game system you’ll download can ask your AI what to do, just as each shape first appears at the top of the board. The game will provide your AI the identity of the shape, along with the current contents of the board. Your AI will then compute the best of all possible placements, using a cost-based algorithm, and provide it to the game.
Implementing an Interface
In previous assignments, you were given a class file with method declarations, Javadoc comments, and placeholder implementations. In this assignment, you’ll be given an
interface instead. An interface contains the method declarations and the Javadoc comments, but no code at all (not even placeholders). Your task is to
implement this interface, which means you’ll develop a class that provides code for all the methods declared in the interface. In addition to the methods specified by the interface, you will likely need to develop several private helper methods in order to fully implement it without redundancies.
System Description
The interface you will implement is called edu.vt.cs5044.tetris.AI and your implementation class must be called edu.vt.cs5044.TetrisAI. You will need to develop the code needed to implement the methods defined by the interface. One of the methods will be the AI system, responsible for choosing the best placement for each shape. The other methods will support this by performing necessary calculations. These support methods would normally be private, and not specified by the interface, but for academic purposes we’re exposing these methods to ease the testing requirements. Speaking of tests, you must create a formal JUnit test file, called edu.vt.cs5044.TetrisAITest.
Downloads
tetris5044.jar
Download tetris5044.jar
library file containing all the compiled game engine classes
tetris5044-api.jar
Download tetris5044-api.jar
library file containing the Javadocs for the game engine
Setting up Eclipse
Download all the files from the links above to your computer, placing them in any convenient folder. Your Eclipse workspace is fine, as long as it’s not within any project folder. Open Eclipse and create a new Java Project for this assignment. As with all our projects, don’t create the
module-info file, if prompted.
Right-click the project and select Build Path | Configure Build Path, then select the Libraries tab. Select “Classpath” then click “Add External JARs” and navigate to where you placed the downloaded JAR files, select tetris5044.jar, and click OK. You should now see that file listed in the Classpath section (along with the JRE System Library in the Modulepath section).
Now click the little triangle to expand the new library, select the node called Javadoc location: (None), and click the “Edit…” button. Here be sure to select “Javadoc in archive” first, then click Browse. Navigate again, this time selecting the tetris5044-api.jar file, and click the “Validate” button. It should tell you the location is “likely valid” so click OK, then OK, to get back to the Libraries tab.
Now select “Classpath” again, then click the “Add Library…” button. Select “JUnit” from the list, then select “JUnit 4” (note: this version is not the default!) and click Finish.
Ensure you see all these libraries now:
· Modulepath
· JRE System Library [JavaSE-xx]
· Classpath
· tetris5044.jar
· Javadoc location:
[path to tetris5044-api.jar]
· JUnit 4
Note that it’s perfectly fine if these appear in a different order within each category, as long as they’re all listed in the correct categories. Click “Apply and Close” to accept this build path and return to your project.
Right-click your project name, select New | Source Folder. (If “Source Folder” isn’t listed as an option, select “Other” and find it in the “Java” section.) Enter the name as “test” and you should see it listed in your project, as a peer to the “src” source folder. Next, add a New | Java Package called “edu.vt.cs5044” within each of these source folders (meaning both “src” and “test” should have the same package).
Shall We Play a Game?
At this point, you can right-click the project name, and select the Run As | Java Application. Several classes will appear, and you should see
Tetris5044 – edu.vt.cs5044.tetris listed near the top. However, you may need to type the first few letters to search for this. Select this class, and click Run to play Tetris!
A game window should appear with an empty game board and a prompt to type ‘P’ to play. Go ahead and try this now, to see the game in action.
NOTE: If the application appears to launch, but the game window doesn’t appear, please ask in Piazza for help. Make sure to mention which OS you’re using. Some OS configurations may require a few additional settings.
Once you type P, you will see a new random shape near the top, slowly falling toward the bottom of the well. There are several alternative keyboard controls you can use, but for now just type ‘A’ and ‘D’ to move the shape left and right, and type ‘W’ to rotate the shape. Once the shape is situated as you wish, you can use ‘S’ (or the space bar) to drop the shape immediately, or you can just enjoy watching the shape fall gently into place. The shape will change color once it’s locked into the board, and can no longer be manipulated.
Notice in the console there is a Welcome message. You can type ‘?’ into the game (click the game screen before doing so, to ensure the game receives the keystroke) at any time to produce a listing in the Eclipse console of all of the available options and keyboard controls. Try this now. Some of these features will be extremely useful during the assignment. You’ll probably notice some interesting options, including a way to enable the Player AI by typing Ctrl-P. When you enable this mode, just before each new shape appears in the game, the AI is asked how to best rotate then position the shape.
Try actually typing Ctrl-P into the game window. If you’re in a game, it will end, and you should see a text warning in the console that your AI implementation couldn’t be found. That’s perfectly understandable at this point, because we haven’t created the AI yet.
Back To Work
Close the game for a moment now, while we get to our coding tasks for a while. First, right-click the edu.vt.cs5044 package of the “src” source folder, and select New | Class.
Before you enter the class name, click the “Add…” button to the right of the Interfaces section. In the search box at the top, type AI and you should soon see the AI interface (in the edu.vt.cs5044.tetris package) selected. Click Ok to add that interface. For now, un-check the option to create “Inherited abstract methods” (if checked) and then enter the class name as TetrisAI and click Finish.
Notice that the new file declaration says public class TetrisAI implements AI. This is what tells Java that we intend to be compatible with any system that can work with the AI interface. You’ll also notice Eclipse is already showing an error on the class declaration line. Click the tiny red X in the margin and double-click “Add unimplemented methods” from the pop-up. This asks Eclipse to generate all the method placeholders for you! (The option you un-checked earlier would have done the same thing; this way you’re able to see exactly what it’s doing.) Save the file, and review your new code. It’s already compatible with the game system, even though all it does is return placeholders. That obviously won’t meet our requirements, but it’s actually plenty to get started. Let’s check whether it’s actually recognized by the game engine.
Launch the application again, and type Ctrl-P to activate the Player AI. Confirm that the console says the Player Mode is now AI. If so, go ahead and type P to start the game.
Well, that’s not very exciting. The console just keeps printing warnings that the AI has selected a null move (which is invalid) for each shape, so we still need to manually place the shapes. That’s fair enough, since all we have are placeholders that Eclipse generated for us, but at least we know the game successfully found our AI, and that it seems to be communicating with it. Close the game again, so we can code a little more.
NOTE: You must close the game and restart it, each time you make any source code changes.
Not Very Deep Thoughts
Let’s at least provide a valid suggestion, even if it’s always exactly the same suggestion. In the findBestPlacement() method, let’s replace the placeholder:
return null;
with this:
return new Placement(Rotation.NONE, 0);
Eclipse may complain that it doesn’t know about the Rotation class yet; if so, just double-click the tiny error icon to import these classes from the “edu.vt.cs5044.tetris” package. That should resolve the error, so save your file again. This really doesn’t seem like much of an improvement, but we’ll try it anyway.
Launch the game and use Ctrl-P then P to see what happens. Notice that it’s placing everything against the left edge (column 0) without any rotation. Also notice that the falling shapes are now a different color, confirming that a valid placement was provided by the AI. Shapes can’t be manipulated by the keyboard in this state.
We’ve taken a very important step here. Our AI is actually playing the game, and placing the shapes automatically for us! Right now, the decisions aren’t very good at all, but things can only get better from here. Close the game once you’re ready to code again.
Read All About It
Obviously we need to examine the shape and the state of the board in order to make some reasonable decisions. Let’s take a look at all those Javadocs that make up the API. In your source file click within the word AI of “implements AI” and type Shift-F2 (Fn + Shift + F2 on Mac). This should open the Javadocs for the AI interface using an internal browser within Eclipse. You can set it to use an external browser, if you prefer, but this is fine for now.
Browse through the Javadocs, to get familiar with the interface, and the classes you’ll be using to implement it. For example, click the findBestPlacement() method of the interface, and you’ll see it actually provides a brief outline of a strategy we can use. Click the “Package” link at the very top of any Javadoc page to see the package overview, then navigate throughout the various pages to see what each class and enum can do, along with the requirements for the interface. A fundamental part of this assignment is to learn how to use Javadocs to explore new libraries, as well as to see how a somewhat larger scale system is divided into multiple classes, each with its own purpose.
NOTE: The class Tetris5044 is for internal use only; you won’t need it at all. Also, classes RandomMode and ShapeStream are only needed for the optional “challenge” section below.
Strategy Games
There’s no such thing as a perfect Tetris strategy, so we won’t even try. We are necessarily taking the
heuristicLinks to an external site.
approach to this problem, and there will necessarily be trade-offs involved. In every placement decision, there are advantages and disadvantages. How can we hope to find anything approaching a “best” placement? Now is probably a good time to look at those other methods you’ll need to implement in the AI interface.
Development Phase 1: Cost Methods
From the API, the remaining methods of the interface are related to making some measurements to evaluate a board position. The idea here is that we’ll compute four distinct “cost” factors, which can measure any arbitrary board. We’ll eventually use these to determine how bad (or good) a particular placement decision might be. We’ll need to develop these cost methods first, before we can hope to have a working AI system.
We’re focusing on TDD in this project, so start with some fairly straightforward test cases to ensure that each individual cost calculation method works. Just construct a test board object, then assert the cost value you expect your implementation to compute.
Please be sure to avoid nested loops in your cost method. This isn’t a specific requirement, and won’t directly reduce your score, but nesting can cause a lot of confusion and wasted time. Also, nesting in these methods will tend to introduce a lot of redundancies, and redundancies will reduce your score!
Important: Although it isn’t strictly necessary to fully complete Phase 1 before beginning Phase 2, it is most highly recommended that you do so. Phase 2 will be extremely difficult to troubleshoot without a properly functional Phase 1.
Development Phase 2: Finding the Best
Once all of your individual cost calculation methods are working exactly as expected, it’s time to put it all together. The findBestPlacement() method will need to iterate through every possible placement of the shape, and determine the board that would result from each placement. It will then measure each resultant board by computing the weighted sum of the cost factors, then choose the placement that resulted in the lowest cost board. That placement will be returned to the game engine.
Unlike Phase 1, here your implementation is expected — but not required — to involve nested loops. There’s no redundancy involved, and it’s a natural solution to this particular problem. Using nesting here will actually reduce the overall complexity of your code.
The weightings noted above are important, because certain cost factors should have more influence on the overall decision than others. At first you can just set all the weights to 1, by simply summing the individual cost factors together. Eventually, once it’s working as expected with equal weights, we’ll need to adjust the weights to achieve better results.
Strategic Limitations
Luck — in the form of randomness — plays a starring role in Tetris. Even with the best of strategies, it’s critical to recognize that some games simply provide a more fortunate sequence of shapes than others. Thus it can be difficult to objectively judge exactly how good a particular strategy might be. The same strategies that do very well in some games may do very poorly in others. To help with this, our implementation provides a set of 4 repeatable “TEST” sequences we can use as a benchmark. The average number of shapes placed from these TEST sequences will act as a very reasonable metric of how well our strategy is working overall.
Teaching to the Test
Eventually we’ll be making a linear combination of our four costs, which just means we multiply each cost value by some weight, then add the weighted costs. The equation is very straightforward:
overallCost = weight1*cost1 + weight2*cost2 + weight3*cost3 + weight4*cost4
Computing the individual costs is described in the API, but what about the weights? As noted above, we can start by simply setting all the weights to 1, and indeed that strategy should place exactly
70.25 shapes, averaged over the four provided TEST sequences. Note that the sequence in which you iterate, and how you handle ties, can affect the outcome. If you’re getting something close, but not exact, please ask in Piazza.
Standards of Learning
Can we do better? Sure! As a start, reasonable weight ranges for the selected factors will be 0 through 12, in increments of 4, meaning you should use combinations of weight values of 0, 4, 8, and 12 for each cost factor. You can just use trial-and-error if you wish; watch your AI play the test games and try to figure out which factors need more or less emphasis. For example, if your AI is creating too many unnecessary gaps, try to increase the weight of the gap count cost factor. Feel free to use Turbo mode to dramatically speed up the testing process.
To earn full credit, your AI must be able to place at least
100 shapes, averaged across the provided TEST sequences. This is an improvement factor of about 40% above the performance when setting all weights to 1. To achieve this, manually adjust the weights. Of all these possible combinations, about 20% will result in an acceptable level of performance, so even just guessing some weight combinations won’t take too long yield a suitable result.
Please note that you can’t (unless you’ve completed the optional challenge below) develop a JUnit test to verify the level of performance of your weight combinations. Instead, you must confirm this by manually, by actually running the game in all four TEST modes, and making note of the displayed number of placements made for each mode. Again, Turbo mode will save a great deal of time during this process.
NOTE: Please do NOT rely upon Web-CAT for this; if you need any help, please ask in Piazza!
Test Coverage
Creating enough JUnit tests to cover all of your code will generally be very straightforward, since there aren’t very many branches involved in the solution. As a result, complete coverage is not nearly enough to ensure that you have correctly implemented your code.
Therefore, you must generate at least 5 test cases, with reasonably complex boards, for each interface method. You can satisfy this by creating at least 5 distinct test boards which you will simply share among assertions involving all the cost methods. You may find it useful to create a separate set of 5 test boards to test your findBestPlacement() method.
The test boards are expected cover a reasonably wide range of board layouts. You’re also encouraged to generate several simple test boards, to exercise cases like an empty board or an almost empty board. These simple boards don’t count toward your required 5 test cases mentioned above. Note that Web-CAT won’t (and can’t) enforce this requirement, but the human grader will definitely be looking for this.
Functional Decomposition
Judicious use of helper methods can significantly reduce the overall amount of code you need to develop, and help eliminate redundancies. Your code will be inspected during the human review for redundancies, so be sure to develop helper methods as appropriate.
help-doc.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
How This API Document Is Organized
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
Package
Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:
Interfaces (italic)
Classes
Enums
Exceptions
Errors
Annotation Types
Class/Interface
Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:
Class inheritance diagram
Direct Subclasses
All Known Subinterfaces
All Known Implementing Classes
Class/interface declaration
Class/interface description
Nested Class Summary
Field Summary
Constructor Summary
Method Summary
Field Detail
Constructor Detail
Method Detail
Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
Annotation Type
Each annotation type has its own separate page with the following sections:
Annotation Type declaration
Annotation Type description
Required Element Summary
Optional Element Summary
Element Detail
Enum
Each enum has its own separate page with the following sections:
Enum declaration
Enum description
Enum Constant Summary
Enum Constant Detail
Use
Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the “Use” link in the navigation bar.
Deprecated API
The
Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
Index
The
Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
Prev/Next
These links take you to the next or previous class, interface, package, or related page.
Frames/No Frames
These links show and hide the HTML frames. All pages are available with or without frames.
All Classes
The
All Classes link shows all classes and interfaces except non-static nested types.
Serialized Form
Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking “Serialized Form” in the “See also” section of the class description.
Constant Field Values
The
Constant Field Values page lists the static final fields and their values.
This help file applies to API documentation generated using the standard doclet.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
constant-values.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
Constant Field Values
Contents
edu.vt.*
edu.vt.*
edu.vt.cs5044.tetris.
Board
Modifier and Type
Constant Field
Value
public static final int
HEIGHT
24
public static final int
HEIGHT_LIMIT
20
public static final int
WIDTH
10
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
allclasses-frame.html
All Classes
AI
Board
Placement
RandomMode
Rotation
Shape
ShapeStream
Tetris5044
index.html
stylesheet.css
/* Javadoc style sheet */
/*
Overall document style
*/
@import url(‘resources/fonts/dejavu.css’);
body {
background-color:#ffffff;
color:#353833;
font-family:’DejaVu Sans’, Arial, Helvetica, sans-serif;
font-size:14px;
margin:0;
}
a:link, a:visited {
text-decoration:none;
color:#4A6782;
}
a:hover, a:focus {
text-decoration:none;
color:#bb7a2a;
}
a:active {
text-decoration:none;
color:#4A6782;
}
a[name] {
color:#353833;
}
a[name]:hover {
text-decoration:none;
color:#353833;
}
pre {
font-family:’DejaVu Sans Mono’, monospace;
font-size:14px;
}
h1 {
font-size:20px;
}
h2 {
font-size:18px;
}
h3 {
font-size:16px;
font-style:italic;
}
h4 {
font-size:13px;
}
h5 {
font-size:12px;
}
h6 {
font-size:11px;
}
ul {
list-style-type:disc;
}
code, tt {
font-family:’DejaVu Sans Mono’, monospace;
font-size:14px;
padding-top:4px;
margin-top:8px;
line-height:1.4em;
}
dt code {
font-family:’DejaVu Sans Mono’, monospace;
font-size:14px;
padding-top:4px;
}
table tr td dt code {
font-family:’DejaVu Sans Mono’, monospace;
font-size:14px;
vertical-align:top;
padding-top:4px;
}
sup {
font-size:8px;
}
/*
Document title and Copyright styles
*/
.clear {
clear:both;
height:0px;
overflow:hidden;
}
.aboutLanguage {
float:right;
padding:0px 21px;
font-size:11px;
z-index:200;
margin-top:-9px;
}
.legalCopy {
margin-left:.5em;
}
.bar a, .bar a:link, .bar a:visited, .bar a:active {
color:#FFFFFF;
text-decoration:none;
}
.bar a:hover, .bar a:focus {
color:#bb7a2a;
}
.tab {
background-color:#0066FF;
color:#ffffff;
padding:8px;
width:5em;
font-weight:bold;
}
/*
Navigation bar styles
*/
.bar {
background-color:#4D7A97;
color:#FFFFFF;
padding:.8em .5em .4em .8em;
height:auto;/*height:1.8em;*/
font-size:11px;
margin:0;
}
.topNav {
background-color:#4D7A97;
color:#FFFFFF;
float:left;
padding:0;
width:100%;
clear:right;
height:2.8em;
padding-top:10px;
overflow:hidden;
font-size:12px;
}
.bottomNav {
margin-top:10px;
background-color:#4D7A97;
color:#FFFFFF;
float:left;
padding:0;
width:100%;
clear:right;
height:2.8em;
padding-top:10px;
overflow:hidden;
font-size:12px;
}
.subNav {
background-color:#dee3e9;
float:left;
width:100%;
overflow:hidden;
font-size:12px;
}
.subNav div {
clear:left;
float:left;
padding:0 0 5px 6px;
text-transform:uppercase;
}
ul.navList, ul.subNavList {
float:left;
margin:0 25px 0 0;
padding:0;
}
ul.navList li{
list-style:none;
float:left;
padding: 5px 6px;
text-transform:uppercase;
}
ul.subNavList li{
list-style:none;
float:left;
}
.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited {
color:#FFFFFF;
text-decoration:none;
text-transform:uppercase;
}
.topNav a:hover, .bottomNav a:hover {
text-decoration:none;
color:#bb7a2a;
text-transform:uppercase;
}
.navBarCell1Rev {
background-color:#F8981D;
color:#253441;
margin: auto 5px;
}
.skipNav {
position:absolute;
top:auto;
left:-9999px;
overflow:hidden;
}
/*
Page header and footer styles
*/
.header, .footer {
clear:both;
margin:0 20px;
padding:5px 0 0 0;
}
.indexHeader {
margin:10px;
position:relative;
}
.indexHeader span{
margin-right:15px;
}
.indexHeader h1 {
font-size:13px;
}
.title {
color:#2c4557;
margin:10px 0;
}
.subTitle {
margin:5px 0 0 0;
}
.header ul {
margin:0 0 15px 0;
padding:0;
}
.footer ul {
margin:20px 0 5px 0;
}
.header ul li, .footer ul li {
list-style:none;
font-size:13px;
}
/*
Heading styles
*/
div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 {
background-color:#dee3e9;
border:1px solid #d0d9e0;
margin:0 0 6px -8px;
padding:7px 5px;
}
ul.blockList ul.blockList ul.blockList li.blockList h3 {
background-color:#dee3e9;
border:1px solid #d0d9e0;
margin:0 0 6px -8px;
padding:7px 5px;
}
ul.blockList ul.blockList li.blockList h3 {
padding:0;
margin:15px 0;
}
ul.blockList li.blockList h2 {
padding:0px 0 20px 0;
}
/*
Page layout container styles
*/
.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer {
clear:both;
padding:10px 20px;
position:relative;
}
.indexContainer {
margin:10px;
position:relative;
font-size:12px;
}
.indexContainer h2 {
font-size:13px;
padding:0 0 3px 0;
}
.indexContainer ul {
margin:0;
padding:0;
}
.indexContainer ul li {
list-style:none;
padding-top:2px;
}
.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt {
font-size:12px;
font-weight:bold;
margin:10px 0 0 0;
color:#4E4E4E;
}
.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd {
margin:5px 0 10px 0px;
font-size:14px;
font-family:’DejaVu Sans Mono’,monospace;
}
.serializedFormContainer dl.nameValue dt {
margin-left:1px;
font-size:1.1em;
display:inline;
font-weight:bold;
}
.serializedFormContainer dl.nameValue dd {
margin:0 0 0 1px;
font-size:1.1em;
display:inline;
}
/*
List styles
*/
ul.horizontal li {
display:inline;
font-size:0.9em;
}
ul.inheritance {
margin:0;
padding:0;
}
ul.inheritance li {
display:inline;
list-style:none;
}
ul.inheritance li ul.inheritance {
margin-left:15px;
padding-left:15px;
padding-top:1px;
}
ul.blockList, ul.blockListLast {
margin:10px 0 10px 0;
padding:0;
}
ul.blockList li.blockList, ul.blockListLast li.blockList {
list-style:none;
margin-bottom:15px;
line-height:1.4;
}
ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList {
padding:0px 20px 5px 10px;
border:1px solid #ededed;
background-color:#f8f8f8;
}
ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList {
padding:0 0 5px 8px;
background-color:#ffffff;
border:none;
}
ul.blockList ul.blockList ul.blockList ul.blockList li.blockList {
margin-left:0;
padding-left:0;
padding-bottom:15px;
border:none;
}
ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast {
list-style:none;
border-bottom:none;
padding-bottom:0;
}
table tr td dl, table tr td dl dt, table tr td dl dd {
margin-top:0;
margin-bottom:1px;
}
/*
Table styles
*/
.overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary {
width:100%;
border-left:1px solid #EEE;
border-right:1px solid #EEE;
border-bottom:1px solid #EEE;
}
.overviewSummary, .memberSummary {
padding:0px;
}
.overviewSummary caption, .memberSummary caption, .typeSummary caption,
.useSummary caption, .constantsSummary caption, .deprecatedSummary caption {
position:relative;
text-align:left;
background-repeat:no-repeat;
color:#253441;
font-weight:bold;
clear:none;
overflow:hidden;
padding:0px;
padding-top:10px;
padding-left:1px;
margin:0px;
white-space:pre;
}
.overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link,
.useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link,
.overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover,
.useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover,
.overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active,
.useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active,
.overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited,
.useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited {
color:#FFFFFF;
}
.overviewSummary caption span, .memberSummary caption span, .typeSummary caption span,
.useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span {
white-space:nowrap;
padding-top:5px;
padding-left:12px;
padding-right:12px;
padding-bottom:7px;
display:inline-block;
float:left;
background-color:#F8981D;
border: none;
height:16px;
}
.memberSummary caption span.activeTableTab span {
white-space:nowrap;
padding-top:5px;
padding-left:12px;
padding-right:12px;
margin-right:3px;
display:inline-block;
float:left;
background-color:#F8981D;
height:16px;
}
.memberSummary caption span.tableTab span {
white-space:nowrap;
padding-top:5px;
padding-left:12px;
padding-right:12px;
margin-right:3px;
display:inline-block;
float:left;
background-color:#4D7A97;
height:16px;
}
.memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab {
padding-top:0px;
padding-left:0px;
padding-right:0px;
background-image:none;
float:none;
display:inline;
}
.overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd,
.useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd {
display:none;
width:5px;
position:relative;
float:left;
background-color:#F8981D;
}
.memberSummary .activeTableTab .tabEnd {
display:none;
width:5px;
margin-right:3px;
position:relative;
float:left;
background-color:#F8981D;
}
.memberSummary .tableTab .tabEnd {
display:none;
width:5px;
margin-right:3px;
position:relative;
background-color:#4D7A97;
float:left;
}
.overviewSummary td, .memberSummary td, .typeSummary td,
.useSummary td, .constantsSummary td, .deprecatedSummary td {
text-align:left;
padding:0px 0px 12px 10px;
}
th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th,
td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{
vertical-align:top;
padding-right:0px;
padding-top:8px;
padding-bottom:3px;
}
th.colFirst, th.colLast, th.colOne, .constantsSummary th {
background:#dee3e9;
text-align:left;
padding:8px 3px 3px 7px;
}
td.colFirst, th.colFirst {
white-space:nowrap;
font-size:13px;
}
td.colLast, th.colLast {
font-size:13px;
}
td.colOne, th.colOne {
font-size:13px;
}
.overviewSummary td.colFirst, .overviewSummary th.colFirst,
.useSummary td.colFirst, .useSummary th.colFirst,
.overviewSummary td.colOne, .overviewSummary th.colOne,
.memberSummary td.colFirst, .memberSummary th.colFirst,
.memberSummary td.colOne, .memberSummary th.colOne,
.typeSummary td.colFirst{
width:25%;
vertical-align:top;
}
td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover {
font-weight:bold;
}
.tableSubHeadingColor {
background-color:#EEEEFF;
}
.altColor {
background-color:#FFFFFF;
}
.rowColor {
background-color:#EEEEEF;
}
/*
Content styles
*/
.description pre {
margin-top:0;
}
.deprecatedContent {
margin:0;
padding:10px 0;
}
Summary {
padding:0;
}
ul.blockList ul.blockList ul.blockList li.blockList h3 {
font-style:normal;
}
div.block {
font-size:14px;
font-family:’DejaVu Serif’, Georgia, “Times New Roman”, Times, serif;
}
td.colLast div {
padding-top:0px;
}
td.colLast a {
padding-bottom:3px;
}
/*
Formatting effect styles
*/
.sourceLineNo {
color:green;
padding:0 30px 0 0;
}
h1.hidden {
visibility:hidden;
overflow:hidden;
font-size:10px;
}
.block {
display:block;
margin:3px 10px 2px 0px;
color:#474747;
}
.deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink,
.overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel,
.seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink {
font-weight:bold;
}
.deprecationComment, .emphasizedPhrase, .interfaceName {
font-style:italic;
}
div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase,
div.block div.block span.interfaceName {
font-style:normal;
}
div.contentContainer ul.blockList li.blockList h2{
padding-bottom:0px;
}
deprecated-list.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
Deprecated API
Contents
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
edu/vt/cs5044/tetris/package-frame.html
edu.vt.cs5044.tetris
Interfaces
AI
Classes
Board
Placement
ShapeStream
Tetris5044
Enums
RandomMode
Rotation
Shape
edu/vt/cs5044/tetris/package-use.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
Uses of Package
edu.vt.cs5044.tetris
Classes in
edu.vt.cs5044.tetris used by
edu.vt.cs5044.tetris
Class and Description
Board
Represents a tetris game board, including all fixed blocks.
Placement
Represents a single possible placement of a shape within the well.
RandomMode
Represents the modes of randomness used for the game.
Rotation
Represents each of the four unique 90° rotations.
Shape
Represents each of the seven distinct tetromino shapes.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
edu/vt/cs5044/tetris/RandomMode.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Enum Constants |
Field |
Method
Detail:
Enum Constants |
Field |
Method
edu.vt.cs5044.tetris
Enum RandomMode
Object
Enum
RandomMode
All Implemented Interfaces:
Serializable, Comparable
public enum RandomMode
extends Enum
Represents the modes of randomness used for the game.
This enum is only meaningful for the OPTIONAL portion of this assignment.
Enum Constant Summary
Enum Constants
Enum Constant and Description
NORMAL
Stream of randomness for normal play.
TEST1
Repeatable stream of randomness (variant 1).
TEST2
Repeatable stream of randomness (variant 2).
TEST3
Repeatable stream of randomness (variant 3).
TEST4
Repeatable stream of randomness (variant 4).
Method Summary
All Methods
Static Methods
Concrete Methods
Modifier and Type
Method and Description
static Set
getTestSet()
Fetch the set of all test-related values.
static
RandomMode
valueOf(String name)
Returns the enum constant of this type with the specified name.
static
RandomMode[]
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
Methods inherited from class Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
Methods inherited from class Object
getClass, notify, notifyAll, wait, wait, wait
Enum Constant Detail
NORMAL
public static final
RandomMode NORMAL
Stream of randomness for normal play. This mode indicates a stream that is not repeatable.
TEST1
public static final
RandomMode TEST1
Repeatable stream of randomness (variant 1).
This is to be used for testing purposes, to ensure consistent results.
TEST2
public static final
RandomMode TEST2
Repeatable stream of randomness (variant 2).
This is to be used for testing purposes, to ensure consistent results.
TEST3
public static final
RandomMode TEST3
Repeatable stream of randomness (variant 3).
This is to be used for testing purposes, to ensure consistent results.
TEST4
public static final
RandomMode TEST4
Repeatable stream of randomness (variant 4).
This is to be used for testing purposes, to ensure consistent results.
Method Detail
values
public static
RandomMode[] values()
Returns an array containing the constants of this enum type, in
the order they are declared. This method may be used to iterate
over the constants as follows:
for (RandomMode c : RandomMode.values())
System.out.println(c);
Returns:
an array containing the constants of this enum type, in the order they are declared
valueOf
public static
RandomMode valueOf(String name)
Returns the enum constant of this type with the specified name.
The string must match exactly an identifier used to declare an
enum constant in this type. (Extraneous whitespace characters are
not permitted.)
Parameters:
name – the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException – if this enum type has no constant with the specified name
NullPointerException – if the argument is null
getTestSet
public static Set getTestSet()
Fetch the set of all test-related values.
This set includes all RandomMode values except NORMAL.
Returns:
set of test-related values.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Enum Constants |
Field |
Method
Detail:
Enum Constants |
Field |
Method
edu/vt/cs5044/tetris/package-summary.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Package
Next Package
Frames
No Frames
All Classes
Package edu.vt.cs5044.tetris
This package holds the various components of the Tetris 5044 game engine.
See:
Description
Interface Summary
Interface
Description
AI
Interface the game engine uses to communicate with AI implementations.
Class Summary
Class
Description
Board
Represents a tetris game board, including all fixed blocks.
Placement
Represents a single possible placement of a shape within the well.
ShapeStream
Generates a stream of random shapes for a tetris game.
Tetris5044
Main class for Tetris 5044.
Enum Summary
Enum
Description
RandomMode
Represents the modes of randomness used for the game.
Rotation
Represents each of the four unique 90° rotations.
Shape
Represents each of the seven distinct tetromino shapes.
Package edu.vt.cs5044.tetris Description
This package holds the various components of the Tetris 5044 game engine.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Package
Next Package
Frames
No Frames
All Classes
edu/vt/cs5044/tetris/Tetris5044.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
edu.vt.cs5044.tetris
Class Tetris5044
Object
Tetris5044
public class Tetris5044
extends Object
Main class for Tetris 5044.
This class is only used to launch the graphical version of the game.
Version:
2022.Spring
Author:
Prof. Oliva
Method Summary
All Methods
Static Methods
Concrete Methods
Modifier and Type
Method and Description
static void
main(String[] args)
Launches the Tetris 5044 application.
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Method Detail
main
public static void main(String[] args)
Launches the Tetris 5044 application.
Parameters:
args – currently ignored
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
edu/vt/cs5044/tetris/AI.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
edu.vt.cs5044.tetris
Interface AI
public interface AI
Interface the game engine uses to communicate with AI implementations.
ACADEMIC NOTE: You must develop an implementation of this interface.
Method Summary
All Methods
Instance Methods
Abstract Methods
Modifier and Type
Method and Description
Placement
findBestPlacement(
Board currentBoard,
Shape shape)
Determine the best placement available for a shape in a board.
int
getAverageColumnHeight(
Board board)
Compute the average height of all the columns of a board (see academic note).
int
getColumnHeightRange(
Board board)
Compute the range of column heights of a board (see academic note).
int
getColumnHeightVariance(
Board board)
Compute the sum of variances of adjacent column heights (see academic note).
int
getTotalGapCount(
Board board)
Compute the total gap count of a board (see academic note).
Method Detail
findBestPlacement
Placement findBestPlacement(
Board currentBoard,
Shape shape)
Determine the best placement available for a shape in a board.
All possible columns for all possible rotations of the given shape should be considered. For
each combination, implementations should call
Board.getResultBoard(Shape, Placement)
to generate the resultant board after a hypothetical placement. The implementation must
calculate a relative cost value for each resultant board, then return the Placement object
associated with the lowest cost (most preferable).
Parameters:
currentBoard – the existing board.
shape – the shape to be placed in the board.
Returns:
the best move as computed by the implementation.
getColumnHeightRange
int getColumnHeightRange(
Board board)
Compute the range of column heights of a board (see academic note).
Finds the height of the tallest and shortest columns within a board. Height is the based on
the largest row number containing a block. Note that if the highest row containing a block
in some column is r, the height of that column is r+1. Columns containing no blocks have
a height of zero. The result is the difference between the tallest and shortest heights.
As an example, the following board has a column height range of 2:
| |
| |
| |
|## ## #|
|# ##### ##|
|#### #####|
|# ##### ##|
|## #######|
|######### |
| #########|
| #########|
|### #####|
|####### ##|
|######## #|
| #### ####|
+———-+
ACADEMIC NOTE: This method would normally be declared as private. We’re exposing it as public
only for formal testing purposes.
Parameters:
board – the Board to evaluate.
Returns:
the difference in height between the tallest column and the shortest column.
getAverageColumnHeight
int getAverageColumnHeight(
Board board)
Compute the average height of all the columns of a board (see academic note).
Sums the total height of all columns of a board, then divides by
the number of columns. Integer division is used, so the result is truncated.
Height is the based on the largest row number containing a block. Note that if the highest
row containing a block in some column is r, the height of that column is r+1.
Columns containing no blocks have a height of zero.
As an example, the following board has an average column height of 11:
| |
| |
| |
|## ## #|
|# ##### ##|
|#### #####|
|# ##### ##|
|## #######|
|######### |
| #########|
| #########|
|### #####|
|####### ##|
|######## #|
| #### ####|
+———-+
ACADEMIC NOTE: This method would normally be declared as private. We’re exposing it as public
only for formal testing purposes.
Parameters:
board – the Board to evaluate.
Returns:
the truncated average height of the columns.
getTotalGapCount
int getTotalGapCount(
Board board)
Compute the total gap count of a board (see academic note).
Counts the number of gaps residing within a board. A gap is a defined as any location without
a block, where a block exists in any higher row of the same column.
As an example, the following board has a total gap count of 14:
| |
| |
| |
|## ## #|
|# ##### ##|
|#### #####|
|# ##### ##|
|## #######|
|######### |
| #########|
| #########|
|### #####|
|####### ##|
|######## #|
| #### ####|
+———-+
ACADEMIC NOTE: This method would normally be declared as private. We’re exposing it as public
only for formal testing purposes.
Parameters:
board – the Board to evaluate.
Returns:
the number of gaps.
getColumnHeightVariance
int getColumnHeightVariance(
Board board)
Compute the sum of variances of adjacent column heights (see academic note).
Computes the sum of the absolute values of differences in heights of
adjacent columns, as measured from either edge of the board to the other. Note that for a
board of width w, there are w-1 adjacent column heights.
Height is the based on the largest row number containing a block. Note that if the highest
row containing a block in some column is r, the height of that column is r+1.
Columns containing no blocks have a height of zero.
As an example, the following board has a column height variance of 6:
| |
| |
| |
|## ## #|
|# ##### ##|
|#### #####|
|# ##### ##|
|## #######|
|######### |
| #########|
| #########|
|### #####|
|####### ##|
|######## #|
| #### ####|
+———-+
ACADEMIC NOTE: This method would normally be declared as private. We’re exposing it as public
only for formal testing purposes.
Parameters:
board – the Board to evaluate.
Returns:
the sum of variances of adjacent column heights.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
edu/vt/cs5044/tetris/ShapeStream.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
edu.vt.cs5044.tetris
Class ShapeStream
Object
ShapeStream
public class ShapeStream
extends Object
Generates a stream of random shapes for a tetris game.
This class is only meaningful for the OPTIONAL portion of this assignment.
Constructor Summary
Constructors
Constructor and Description
ShapeStream(
RandomMode mode)
Construct a new ShapeStream in the specified RandomMode.
Method Summary
All Methods
Instance Methods
Concrete Methods
Modifier and Type
Method and Description
Shape
nextShape()
Fetch the next random Shape from this stream.
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
ShapeStream
public ShapeStream(
RandomMode mode)
Construct a new ShapeStream in the specified RandomMode.
Parameters:
mode – specifies the source of randomness for the stream; must not be null.
Method Detail
nextShape
public
Shape nextShape()
Fetch the next random Shape from this stream.
Returns:
the next random Shape from this stream.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
edu/vt/cs5044/tetris/Board.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
edu.vt.cs5044.tetris
Class Board
Object
Board
public class Board
extends Object
Represents a tetris game board, including all fixed blocks.
This class is effectively immutable, because there are no public mutators.
Field Summary
Fields
Modifier and Type
Field and Description
static int
HEIGHT
Height of the game board, in blocks.
static int
HEIGHT_LIMIT
Height limit of the game board, in blocks.
static int
WIDTH
Width of the game board, in blocks.
Constructor Summary
Constructors
Constructor and Description
Board()
Construct a new empty board.
Board(String… initialBlocks)
Construct a new board with the specified initial blocks.
Method Summary
All Methods
Instance Methods
Concrete Methods
Modifier and Type
Method and Description
boolean
equals(Object obj)
Test for equivalence with another Board.
boolean[][]
getFixedBlocks()
Fetch a two-dimensional boolean array representing the fixed blocks of the board.
Board
getResultBoard(
Shape shape,
Placement place)
Generate a new board that is the result of placing a new shape in this board.
int
hashCode()
Hash code for this Board.
String
toString()
Generate a multi-line ASCII art visualization of this board.
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Field Detail
WIDTH
public static final int WIDTH
Width of the game board, in blocks.
See Also:
Constant Field Values
HEIGHT
public static final int HEIGHT
Height of the game board, in blocks.
See Also:
Constant Field Values
HEIGHT_LIMIT
public static final int HEIGHT_LIMIT
Height limit of the game board, in blocks.
If any block becomes fixed at or above this row index during normal play, the game ends.
See Also:
Constant Field Values
Constructor Detail
Board
public Board()
Construct a new empty board.
The constructed Board object will contain no fixed blocks.
Board
public Board(String… initialBlocks)
Construct a new board with the specified initial blocks.
Specify a variable number of String values as arguments. Each String represents one row of
the board.
The last row specified is placed at the bottom (row index 0) of the board. No more than
HEIGHT rows may be specified. If fewer rows are specified, the unspecified rows will be
empty.
Each row must have exactly WIDTH characters. The first character represents the left edge of
the board. Each character must be either a space ‘ ‘ or a hash ‘#’. A hash means a single
fixed block exists at that position. A space means no fixed block exists at that position.
Parameters:
initialBlocks – blocks to include in the board
Method Detail
getFixedBlocks
public boolean[][] getFixedBlocks()
Fetch a two-dimensional boolean array representing the fixed blocks of the board.
The array is arranged such that the first index selects the column, and the second index
selects the row. The left-most column is index 0, and the bottom-most row is index 0. The
right-most column index is WIDTH – 1, and the top-most row index is HEIGHT – 1.
A boolean value of true within the array indicates the presence of a fixed block at that
location within the board; a false value within the array indicates there is no block present
at that location
As an example of using the returned value, array[3][1] will be true if there is a block
present at the intersection of column index 3 (the fourth column, counting from the left)
with row index 1 (the second row, counting from the bottom), or false if there is no block.
NOTE: The returned array is mutable, but mutating it will not affect the Board object.
Returns:
a 2D boolean array representing the fixed columns of the board.
getResultBoard
public
Board getResultBoard(
Shape shape,
Placement place)
Generate a new board that is the result of placing a new shape in this board.
First a copy of this board is created. The Shape is placed at the top of this copy, rotated
according to the Placement rotation, then moved horizontally such that the left-most block is
in the Placement column. The block is then dropped until it locks into place, then all
completely full rows (if any) are cleared as in normal play. The copy, after this activity
has been performed on it, is returned.
Note: This method is NOT a mutator. It does not change the original Board
object in any way.
Parameters:
shape – the Shape to place.
place – a Placement containing the rotation and horizontal location for the shape.
Returns:
a new Board representing the result of the placement.
toString
public String toString()
Generate a multi-line ASCII art visualization of this board.
The walls of the board are represented as ‘*’ characters above the HEIGHT_LIMIT, and as ‘|’
characters otherwise. The bottom of the board is represented by a row of ‘-‘ characters.
Fixed blocks are represented by ‘#’ characters; empty locations are represented by spaces.
ACADEMIC NOTE: This is for troubleshooting purposes ONLY. This is NOT meant
to be used for testing via JUnit, nor for the optional challenge.
Overrides:
toString in class Object
Returns:
a rudimentary ASCII art depiction of the board.
equals
public boolean equals(Object obj)
Test for equivalence with another Board.
Two boards are equivalent if and only if they contain the same arrangement of fixed blocks.
This method is consistent with the hashCode() implementation, and so is suitable for use
within a HashSet or HashMap.
Overrides:
equals in class Object
Parameters:
obj – the other board object.
Returns:
true if the boards are equivalent; false otherwise.
hashCode
public int hashCode()
Hash code for this Board.
The result is consistent with equals() and so Board objects are suitable for use within a
HashSet or HashMap.
Overrides:
hashCode in class Object
Returns:
hash code for this Board object.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
edu/vt/cs5044/tetris/Rotation.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Enum Constants |
Field |
Method
Detail:
Enum Constants |
Field |
Method
edu.vt.cs5044.tetris
Enum Rotation
Object
Enum
Rotation
All Implemented Interfaces:
Serializable, Comparable
public enum Rotation
extends Enum
Represents each of the four unique 90° rotations.
Enum Constant Summary
Enum Constants
Enum Constant and Description
CCW_180
Rotate 180° counter-clockwise.
CCW_270
Rotate 270° counter-clockwise.
CCW_90
Rotate 90° counter-clockwise.
NONE
No rotation; the default orientation.
Method Summary
All Methods
Static Methods
Concrete Methods
Modifier and Type
Method and Description
static
Rotation
valueOf(String name)
Returns the enum constant of this type with the specified name.
static
Rotation[]
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
Methods inherited from class Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
Methods inherited from class Object
getClass, notify, notifyAll, wait, wait, wait
Enum Constant Detail
NONE
public static final
Rotation NONE
No rotation; the default orientation.
CCW_90
public static final
Rotation CCW_90
Rotate 90° counter-clockwise.
CCW_180
public static final
Rotation CCW_180
Rotate 180° counter-clockwise.
CCW_270
public static final
Rotation CCW_270
Rotate 270° counter-clockwise.
Method Detail
values
public static
Rotation[] values()
Returns an array containing the constants of this enum type, in
the order they are declared. This method may be used to iterate
over the constants as follows:
for (Rotation c : Rotation.values())
System.out.println(c);
Returns:
an array containing the constants of this enum type, in the order they are declared
valueOf
public static
Rotation valueOf(String name)
Returns the enum constant of this type with the specified name.
The string must match exactly an identifier used to declare an
enum constant in this type. (Extraneous whitespace characters are
not permitted.)
Parameters:
name – the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException – if this enum type has no constant with the specified name
NullPointerException – if the argument is null
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Enum Constants |
Field |
Method
Detail:
Enum Constants |
Field |
Method
edu/vt/cs5044/tetris/Placement.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
edu.vt.cs5044.tetris
Class Placement
Object
Placement
public class Placement
extends Object
Represents a single possible placement of a shape within the well.
The placement is specified by a rotation, along with the horizontal location of the left-most
block of the rotated shape. This class is immutable.
Constructor Summary
Constructors
Constructor and Description
Placement(
Rotation rotation,
int column)
Construct a new Placement from the arguments provided.
Method Summary
All Methods
Instance Methods
Concrete Methods
Modifier and Type
Method and Description
boolean
equals(Object obj)
Test for equivalence with another Placement.
int
getColumn()
Fetch the specified column index.
Rotation
getRotation()
Fetch the specified rotation.
int
hashCode()
Hash code for this Placement.
String
toString()
Generates a simple human-readable representation of this object.
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Constructor Detail
Placement
public Placement(
Rotation rotation,
int column)
Construct a new Placement from the arguments provided.
The specified rotation is performed before the horizontal movement to the specified column.
Parameters:
rotation – specifies the rotation to be applied to the shape.
column – left-most block of the rotated shape goes in this column index.
Method Detail
getRotation
public
Rotation getRotation()
Fetch the specified rotation.
Returns:
rotation.
getColumn
public int getColumn()
Fetch the specified column index.
Note that the left-most column of the board is 0. The left-most block of the rotated shape
goes in the specified column index.
Returns:
column.
toString
public String toString()
Generates a simple human-readable representation of this object.
Overrides:
toString in class Object
Returns:
simple representation of this object.
equals
public boolean equals(Object obj)
Test for equivalence with another Placement.
Two placements are equivalent if and only if they contain the same column and same rotation
values. This method is consistent with the hashCode() implementation, and so is suitable for
use within a HashSet or HashMap.
Overrides:
equals in class Object
Parameters:
obj – the other placement.
Returns:
true if the placements are equivalent; false otherwise.
hashCode
public int hashCode()
Hash code for this Placement.
The result is consistent with equals() and so Placement objects are suitable for use within a
HashSet or HashMap.
Overrides:
hashCode in class Object
Returns:
hash code for this Placement object.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Field |
Constr |
Method
Detail:
Field |
Constr |
Method
edu/vt/cs5044/tetris/Shape.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Enum Constants |
Field |
Method
Detail:
Enum Constants |
Field |
Method
edu.vt.cs5044.tetris
Enum Shape
Object
Enum
Shape
All Implemented Interfaces:
Serializable, Comparable
public enum Shape
extends Enum
Represents each of the seven distinct tetromino shapes.
Enum Constant Summary
Enum Constants
Enum Constant and Description
I
The “I” shape.
J
The “J” shape.
L
The “L” shape.
O
The “O” shape.
S
The “S” shape.
T
The “T” shape.
Z
The “Z” shape.
Method Summary
All Methods
Static Methods
Instance Methods
Concrete Methods
Modifier and Type
Method and Description
Set
getValidRotationSet()
Get the set of valid rotations for this shape.
int
getWidth(
Rotation rotation)
Get the width of this shape, in blocks, after applying a specified rotation.
static
Shape
valueOf(String name)
Returns the enum constant of this type with the specified name.
static
Shape[]
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
Methods inherited from class Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
Methods inherited from class Object
getClass, notify, notifyAll, wait, wait, wait
Enum Constant Detail
I
public static final
Shape I
The “I” shape.
In the default orientation, it looks like this:
#
#
#
#
O
public static final
Shape O
The “O” shape.
In the default orientation, it looks like this:
##
##
T
public static final
Shape T
The “T” shape.
In the default orientation, it looks like this:
#
###
J
public static final
Shape J
The “J” shape.
In the default orientation, it looks like this:
#
#
##
L
public static final
Shape L
The “L” shape.
In the default orientation, it looks like this:
#
#
##
S
public static final
Shape S
The “S” shape.
In the default orientation, it looks like this:
##
##
Z
public static final
Shape Z
The “Z” shape.
In the default orientation, it looks like this:
##
##
Method Detail
values
public static
Shape[] values()
Returns an array containing the constants of this enum type, in
the order they are declared. This method may be used to iterate
over the constants as follows:
for (Shape c : Shape.values())
System.out.println(c);
Returns:
an array containing the constants of this enum type, in the order they are declared
valueOf
public static
Shape valueOf(String name)
Returns the enum constant of this type with the specified name.
The string must match exactly an identifier used to declare an
enum constant in this type. (Extraneous whitespace characters are
not permitted.)
Parameters:
name – the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException – if this enum type has no constant with the specified name
NullPointerException – if the argument is null
getValidRotationSet
public Set getValidRotationSet()
Get the set of valid rotations for this shape.
Returns a set of Rotation values that can be applied to this shape to result in
distinct orientations.
Returns:
the a set of valid Rotation values.
getWidth
public int getWidth(
Rotation rotation)
Get the width of this shape, in blocks, after applying a specified rotation.
The rotation parameter must be contained in the Set returned by
getValidRotationSet().
Parameters:
rotation – the rotation to apply.
Returns:
the width of the rotated shape, in blocks.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev Class
Next Class
Frames
No Frames
All Classes
Summary:
Nested |
Enum Constants |
Field |
Method
Detail:
Enum Constants |
Field |
Method
edu/vt/cs5044/tetris/class-use/RandomMode.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
Uses of Class
edu.vt.cs5044.tetris.RandomMode
Uses of
RandomMode in
edu.vt.cs5044.tetris
Methods in
edu.vt.cs5044.tetris that return
RandomMode
Modifier and Type
Method and Description
static
RandomMode
RandomMode.
valueOf(String name)
Returns the enum constant of this type with the specified name.
static
RandomMode[]
RandomMode.
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
Methods in
edu.vt.cs5044.tetris that return types with arguments of type
RandomMode
Modifier and Type
Method and Description
static Set
RandomMode.
getTestSet()
Fetch the set of all test-related values.
Constructors in
edu.vt.cs5044.tetris with parameters of type
RandomMode
Constructor and Description
ShapeStream(
RandomMode mode)
Construct a new ShapeStream in the specified RandomMode.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
edu/vt/cs5044/tetris/class-use/Tetris5044.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
Uses of Class
edu.vt.cs5044.tetris.Tetris5044
No usage of edu.vt.cs5044.tetris.Tetris5044
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
edu/vt/cs5044/tetris/class-use/AI.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
Uses of Interface
edu.vt.cs5044.tetris.AI
No usage of edu.vt.cs5044.tetris.AI
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
edu/vt/cs5044/tetris/class-use/ShapeStream.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
Uses of Class
edu.vt.cs5044.tetris.ShapeStream
No usage of edu.vt.cs5044.tetris.ShapeStream
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
edu/vt/cs5044/tetris/class-use/Board.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
Uses of Class
edu.vt.cs5044.tetris.Board
Uses of
Board in
edu.vt.cs5044.tetris
Methods in
edu.vt.cs5044.tetris that return
Board
Modifier and Type
Method and Description
Board
Board.
getResultBoard(
Shape shape,
Placement place)
Generate a new board that is the result of placing a new shape in this board.
Methods in
edu.vt.cs5044.tetris with parameters of type
Board
Modifier and Type
Method and Description
Placement
AI.
findBestPlacement(
Board currentBoard,
Shape shape)
Determine the best placement available for a shape in a board.
int
AI.
getAverageColumnHeight(
Board board)
Compute the average height of all the columns of a board (see academic note).
int
AI.
getColumnHeightRange(
Board board)
Compute the range of column heights of a board (see academic note).
int
AI.
getColumnHeightVariance(
Board board)
Compute the sum of variances of adjacent column heights (see academic note).
int
AI.
getTotalGapCount(
Board board)
Compute the total gap count of a board (see academic note).
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
edu/vt/cs5044/tetris/class-use/Rotation.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
Uses of Class
edu.vt.cs5044.tetris.Rotation
Uses of
Rotation in
edu.vt.cs5044.tetris
Methods in
edu.vt.cs5044.tetris that return
Rotation
Modifier and Type
Method and Description
Rotation
Placement.
getRotation()
Fetch the specified rotation.
static
Rotation
Rotation.
valueOf(String name)
Returns the enum constant of this type with the specified name.
static
Rotation[]
Rotation.
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
Methods in
edu.vt.cs5044.tetris that return types with arguments of type
Rotation
Modifier and Type
Method and Description
Set
Shape.
getValidRotationSet()
Get the set of valid rotations for this shape.
Methods in
edu.vt.cs5044.tetris with parameters of type
Rotation
Modifier and Type
Method and Description
int
Shape.
getWidth(
Rotation rotation)
Get the width of this shape, in blocks, after applying a specified rotation.
Constructors in
edu.vt.cs5044.tetris with parameters of type
Rotation
Constructor and Description
Placement(
Rotation rotation,
int column)
Construct a new Placement from the arguments provided.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
edu/vt/cs5044/tetris/class-use/Placement.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
Uses of Class
edu.vt.cs5044.tetris.Placement
Uses of
Placement in
edu.vt.cs5044.tetris
Methods in
edu.vt.cs5044.tetris that return
Placement
Modifier and Type
Method and Description
Placement
AI.
findBestPlacement(
Board currentBoard,
Shape shape)
Determine the best placement available for a shape in a board.
Methods in
edu.vt.cs5044.tetris with parameters of type
Placement
Modifier and Type
Method and Description
Board
Board.
getResultBoard(
Shape shape,
Placement place)
Generate a new board that is the result of placing a new shape in this board.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
edu/vt/cs5044/tetris/class-use/Shape.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
Uses of Class
edu.vt.cs5044.tetris.Shape
Uses of
Shape in
edu.vt.cs5044.tetris
Methods in
edu.vt.cs5044.tetris that return
Shape
Modifier and Type
Method and Description
Shape
ShapeStream.
nextShape()
Fetch the next random Shape from this stream.
static
Shape
Shape.
valueOf(String name)
Returns the enum constant of this type with the specified name.
static
Shape[]
Shape.
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
Methods in
edu.vt.cs5044.tetris with parameters of type
Shape
Modifier and Type
Method and Description
Placement
AI.
findBestPlacement(
Board currentBoard,
Shape shape)
Determine the best placement available for a shape in a board.
Board
Board.
getResultBoard(
Shape shape,
Placement place)
Generate a new board that is the result of placing a new shape in this board.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
script.js
function show(type)
{
count = 0;
for (var key in methods) {
var row = document.getElementById(key);
if ((methods[key] & type) != 0) {
row.style.display = ”;
row.className = (count++ % 2) ? rowColor : altColor;
}
else
row.style.display = ‘none’;
}
updateTabs(type);
}
function updateTabs(type)
{
for (var value in tabs) {
var sNode = document.getElementById(tabs[value][0]);
var spanNode = sNode.firstChild;
if (value == type) {
sNode.className = activeTableTab;
spanNode.innerHTML = tabs[value][1];
}
else {
sNode.className = tableTab;
spanNode.innerHTML = “” + tabs[value][1] + ““;
}
}
}
index-all.html
JavaScript is disabled on your browser.
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
A
B
E
F
G
H
M
N
P
R
S
T
V
W
A
AI – Interface in
edu.vt.cs5044.tetris
Interface the game engine uses to communicate with AI implementations.
B
Board – Class in
edu.vt.cs5044.tetris
Represents a tetris game board, including all fixed blocks.
Board() – Constructor for class
Board
Construct a new empty board.
Board(String…) – Constructor for class
Board
Construct a new board with the specified initial blocks.
E
edu.vt.cs5044.tetris – package edu.vt.cs5044.tetris
This package holds the various components of the Tetris 5044 game engine.
equals(Object) – Method in class
Board
Test for equivalence with another Board.
equals(Object) – Method in class
Placement
Test for equivalence with another Placement.
F
findBestPlacement(Board, Shape) – Method in interface
AI
Determine the best placement available for a shape in a board.
G
getAverageColumnHeight(Board) – Method in interface
AI
Compute the average height of all the columns of a board (see academic note).
getColumn() – Method in class
Placement
Fetch the specified column index.
getColumnHeightRange(Board) – Method in interface
AI
Compute the range of column heights of a board (see academic note).
getColumnHeightVariance(Board) – Method in interface
AI
Compute the sum of variances of adjacent column heights (see academic note).
getFixedBlocks() – Method in class
Board
Fetch a two-dimensional boolean array representing the fixed blocks of the board.
getResultBoard(Shape, Placement) – Method in class
Board
Generate a new board that is the result of placing a new shape in this board.
getRotation() – Method in class
Placement
Fetch the specified rotation.
getTestSet() – Static method in enum
RandomMode
Fetch the set of all test-related values.
getTotalGapCount(Board) – Method in interface
AI
Compute the total gap count of a board (see academic note).
getValidRotationSet() – Method in enum
Shape
Get the set of valid rotations for this shape.
getWidth(Rotation) – Method in enum
Shape
Get the width of this shape, in blocks, after applying a specified rotation.
H
hashCode() – Method in class
Board
Hash code for this Board.
hashCode() – Method in class
Placement
Hash code for this Placement.
HEIGHT – Static variable in class
Board
Height of the game board, in blocks.
HEIGHT_LIMIT – Static variable in class
Board
Height limit of the game board, in blocks.
M
main(String[]) – Static method in class
Tetris5044
Launches the Tetris 5044 application.
N
nextShape() – Method in class
ShapeStream
Fetch the next random Shape from this stream.
P
Placement – Class in
edu.vt.cs5044.tetris
Represents a single possible placement of a shape within the well.
Placement(Rotation, int) – Constructor for class
Placement
Construct a new Placement from the arguments provided.
R
RandomMode – Enum in
edu.vt.cs5044.tetris
Represents the modes of randomness used for the game.
Rotation – Enum in
edu.vt.cs5044.tetris
Represents each of the four unique 90° rotations.
S
Shape – Enum in
edu.vt.cs5044.tetris
Represents each of the seven distinct tetromino shapes.
ShapeStream – Class in
edu.vt.cs5044.tetris
Generates a stream of random shapes for a tetris game.
ShapeStream(RandomMode) – Constructor for class
ShapeStream
Construct a new ShapeStream in the specified RandomMode.
T
Tetris5044 – Class in
edu.vt.cs5044.tetris
Main class for Tetris 5044.
toString() – Method in class
Board
Generate a multi-line ASCII art visualization of this board.
toString() – Method in class
Placement
Generates a simple human-readable representation of this object.
V
valueOf(String) – Static method in enum
RandomMode
Returns the enum constant of this type with the specified name.
valueOf(String) – Static method in enum
Rotation
Returns the enum constant of this type with the specified name.
valueOf(String) – Static method in enum
Shape
Returns the enum constant of this type with the specified name.
values() – Static method in enum
RandomMode
Returns an array containing the constants of this enum type, in
the order they are declared.
values() – Static method in enum
Rotation
Returns an array containing the constants of this enum type, in
the order they are declared.
values() – Static method in enum
Shape
Returns an array containing the constants of this enum type, in
the order they are declared.
W
WIDTH – Static variable in class
Board
Width of the game board, in blocks.
A
B
E
F
G
H
M
N
P
R
S
T
V
W
Skip navigation links
Package
Class
Use
Deprecated
Index
Help
Prev
Next
Frames
No Frames
All Classes
package-list
edu.vt.cs5044.tetris
allclasses-noframe.html
All Classes
AI
Board
Placement
RandomMode
Rotation
Shape
ShapeStream
Tetris5044
META-INF/MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.10.4
Created-By: 11.0.2+9 (Oracle Corporation)
Main-Class: edu.vt.cs5044.tetris.Tetris5044
edu/vt/cs5044/tetris/AI.class
package edu.vt.cs5044.tetris;
public
abstract
interface AI {
public
abstract Placement
findBestPlacement(Board, Shape);
public
abstract int
getColumnHeightRange(Board);
public
abstract int
getAverageColumnHeight(Board);
public
abstract int
getTotalGapCount(Board);
public
abstract int
getColumnHeightVariance(Board);
}
edu/vt/cs5044/tetris/Board.class
package edu.vt.cs5044.tetris;
public
synchronized
class Board {
public
static
final int
WIDTH = 10;
public
static
final int
HEIGHT = 24;
public
static
final int
HEIGHT_LIMIT = 20;
private
final java.util.Set
blockSet;
private boolean[][]
fixedBlocksCache;
private boolean
validCache;
public void Board();
void Board(Board);
Board
getCopy();
public
transient void Board(String[]);
private boolean
isCollision(Piece, Coordinate);
public boolean[][]
getFixedBlocks();
public Board
getResultBoard(Shape, Placement);
void
clear();
boolean
isValidMove(Placement, Piece);
java.util.Set
getBlockSet();
void
addBlocks(java.util.Set);
private boolean
isRowFilled(int);
private void
shiftRowsDownTo(int);
int
clearRows();
public String
toString();
public boolean
equals(Object);
public int
hashCode();
}
edu/vt/cs5044/tetris/Coordinate.class
package edu.vt.cs5044.tetris;
final
synchronized
class Coordinate {
private
final int
x;
private
final int
y;
static Coordinate
at(int, int);
static Coordinate
at(Coordinate);
private void Coordinate(int, int);
int
getX();
int
getY();
Coordinate
shiftLeft();
Coordinate
shiftRight();
Coordinate
shiftUp();
Coordinate
shiftDown();
Coordinate
relativeTo(Coordinate);
public String
toString();
public boolean
equals(Object);
public int
hashCode();
}
edu/vt/cs5044/tetris/GameComponent.class
package edu.vt.cs5044.tetris;
synchronized
class GameComponent
extends javax.swing.JComponent {
private
final java.awt.Font
BASE_FONT;
private
final java.awt.Rectangle
tempRectangle;
private
final java.awt.Color
DARK_BLUE;
private
final java.awt.Color
ALICE_BLUE;
private
final java.awt.Color
SLATE_GRAY;
private
final java.awt.Color
LIGHT_CORAL;
private
final java.awt.Color
SILVER;
private
final java.awt.Dimension
PREFERRED_SIZE;
private
final GameManager
manager;
private int
x;
private int
y;
private int
w;
private int
h;
void GameComponent(GameManager);
private void
setup();
public void
paintComponent(java.awt.Graphics);
private void
coordToRect(Coordinate, java.awt.Rectangle);
public java.awt.Dimension
getPreferredSize();
}
edu/vt/cs5044/tetris/GameManager$1.class
package edu.vt.cs5044.tetris;
synchronized
class GameManager$1
extends java.awt.event.KeyAdapter {
void GameManager$1(GameManager);
public void
keyPressed(java.awt.event.KeyEvent);
public void
keyTyped(java.awt.event.KeyEvent);
}
edu/vt/cs5044/tetris/GameManager.class
package edu.vt.cs5044.tetris;
synchronized
class GameManager {
private
final Board
board;
private boolean
inProgress;
private AI
brain;
private boolean
brainActive;
private int
speedLevel;
private boolean
turboActive;
private RandomMode
randomMode;
private ShapeStream
shapeStream;
private int
score;
private UserPlacement
userPlace;
private Placement
compPlace;
private GameComponent
gameComp;
private
final javax.swing.Timer
timer;
void GameManager();
private int
speedToTime(int);
private void
tick(java.awt.event.ActionEvent);
void
setGameComponent(GameComponent);
private void
startGame();
private void
stopGame();
private boolean
isGameOver();
boolean
hasCompPlace();
private void
nextShape();
private void
lockPiece();
private void
drop();
private void
shiftLeft();
private void
shiftRight();
private void
rotate();
private RandomMode
nextRandom();
UserPlacement
getUserPlacement();
Board
getBoard();
int
getScore();
boolean
isInProgress();
}
edu/vt/cs5044/tetris/Piece.class
package edu.vt.cs5044.tetris;
synchronized
class Piece {
private
final Shape
shape;
private
final Rotation
rotation;
private
final int
minX;
private
final int
maxX;
private
final int
minY;
private
final int
maxY;
private
final java.util.Set
blockSet;
void Piece(Shape, Rotation);
Piece
nextRotation();
Shape
getShape();
Rotation
getRotation();
java.util.Set
getBlocks();
int
getWidth();
int
getHeight();
int
getMaxX();
int
getMinX();
int
getMaxY();
int
getMinY();
public boolean
equals(Object);
public int
hashCode();
public String
toString();
}
edu/vt/cs5044/tetris/Placement.class
package edu.vt.cs5044.tetris;
public
synchronized
class Placement {
private
final Rotation
rotation;
private
final int
column;
public void Placement(Rotation, int);
public Rotation
getRotation();
public int
getColumn();
public String
toString();
public boolean
equals(Object);
public int
hashCode();
}
edu/vt/cs5044/tetris/RandomMode$1.class
package edu.vt.cs5044.tetris;
synchronized
class RandomMode$1 {
static void
();
}
edu/vt/cs5044/tetris/RandomMode.class
package edu.vt.cs5044.tetris;
public
final
synchronized
enum RandomMode {
public
static
final RandomMode
NORMAL;
public
static
final RandomMode
TEST1;
public
static
final RandomMode
TEST2;
public
static
final RandomMode
TEST3;
public
static
final RandomMode
TEST4;
private
final int
value;
public
static RandomMode[]
values();
public
static RandomMode
valueOf(String);
private void RandomMode(String, int, int);
RandomMode
next();
int
getValue();
public
static java.util.Set
getTestSet();
static void
();
}
edu/vt/cs5044/tetris/Rotation$1.class
package edu.vt.cs5044.tetris;
synchronized
class Rotation$1 {
static void
();
}
edu/vt/cs5044/tetris/Rotation.class
package edu.vt.cs5044.tetris;
public
final
synchronized
enum Rotation {
public
static
final Rotation
NONE;
public
static
final Rotation
CCW_90;
public
static
final Rotation
CCW_180;
public
static
final Rotation
CCW_270;
private
final int
value;
public
static Rotation[]
values();
public
static Rotation
valueOf(String);
private void Rotation(String, int, int);
int
getValue();
Rotation
getNext();
static void
();
}
edu/vt/cs5044/tetris/Shape.class
package edu.vt.cs5044.tetris;
public
final
synchronized
enum Shape {
public
static
final Shape
I;
public
static
final Shape
O;
public
static
final Shape
T;
public
static
final Shape
J;
public
static
final Shape
L;
public
static
final Shape
S;
public
static
final Shape
Z;
private
final java.util.List
coordSetList;
private
final java.util.Set
rotationSet;
public
static Shape[]
values();
public
static Shape
valueOf(String);
private
transient void Shape(String, int, java.util.List[]);
public java.util.Set
getValidRotationSet();
public int
getWidth(Rotation);
int
countOrientations();
java.util.Set
getBlocks(int);
static void
();
}
edu/vt/cs5044/tetris/ShapeStream.class
package edu.vt.cs5044.tetris;
public
synchronized
class ShapeStream {
private
final java.util.Random
random;
public void ShapeStream(RandomMode);
public Shape
nextShape();
}
edu/vt/cs5044/tetris/Tetris5044.class
package edu.vt.cs5044.tetris;
public
synchronized
class Tetris5044 {
private void Tetris5044();
private
static void
createGui();
public
static void
main(String[]);
}
edu/vt/cs5044/tetris/UserPlacement.class
package edu.vt.cs5044.tetris;
synchronized
class UserPlacement {
private
final Board
board;
private Piece
piece;
private Coordinate
coord;
void UserPlacement(Board, Piece);
void UserPlacement(Board, Piece, int);
Coordinate
getCoordinate();
Piece
getPiece();
private boolean
isBoardCollision(Piece, Coordinate);
void
lockIntoBoard();
void
rotate();
void
shiftLeft();
void
shiftRight();
boolean
shiftDown();
}
edu/vt/cs5044/tetris/package-info.class
package edu.vt.cs5044.tetris;
interface package-info {
}
Place an order in 3 easy steps. Takes less than 5 mins.