Professional Documents
Culture Documents
Submitted in partial fulfillment of the requirements for the VI Semester of degree of Bachelor
of Engineering in Information Science and Engineering of Visvesvaraya Technological
University, Belagavi
Submitted by
SANJEEV J 1AM18IS049
PRASHANTH M 1AM18IS037
Mrs Mala B A
Assistant Professor
Department of ISE
CERTIFICATE
Certified that the mini project work entitled TETRIS GAME has been successfully
completed by SANJEEV J (1AM18IS049), PRASHANTH M (1AM18IS037) bonafide
students of AMC Engineering College, Bengaluru in partial fulfillment of the
requirements for the award of degree in Bachelor of Engineering in Information
Science and Engineering of Visvesvaraya Technological University, Belgaum during
academic year 2020-2021. The project report has been approved as it satisfies the
academic requirements in respect of project work for the said degree.
External Viva
Name of the Examiners Signature with Date
1. ___________________________ 1. ______________________
2. ___________________________ 2. ______________________
DECLARATION
Place : Bengaluru
Date :
SANJEEV J (1AM18IS049)
PRASHANTH M (1AM18IS037)
ACKNOWLEDGMENT
At the very onset we would like to place our gratefulness to all those people who
helped us in making this project a successful one.
Coming up, this project to be a success was not easy. Apart from the shear
effort, the enlightenment of our very experienced teachers also plays a paramount role
because it is they who guide us in the right direction.
In this regard, we express our sincere gratitude to the Director Dr. K M Babu
and the principal Dr.Girisha C, for providing us all the facilities in this college.
We thank our beloved friends for having supported us with all their strength
and might. Last but not the least; we thank our parents for supporting and encouraging
us throughout. We made an honest effort in this assignment.
SANJEEV J (1AM18IS049)
PRASHANTH M (1AM18IS037)
ABSTRACT
Tetris is a puzzle game in which geometric shapes called "tetrominoes" fall down onto a
playing field, and the player has to arrange them to form gapless lines. Pajitnov took
inspiration from pentomino, a classic puzzle game consisting of all the different shapes
that can be made by combining five squares – 12 in total – with the goal of arranging
them in a wooden box like a jigsaw puzzle.
To simplify things, he knocked that down to four squares, thus reducing the number of
shapes from 12 to seven. He called the game Tetris, combining the Greek numeral "tetra"
(meaning four) and tennis, his favorite sport.Pajitnov himself was immediately hooked. "I
couldn't stop myself from playing this prototype version, because it was very addictive to
put the shapes together.
Table of Contents
CERTIFICATE……………………………………………………………..i
DECLARATION…………………………………………………………...ii
ACKNOWLEDGMENT…………………………………………………..iii
ABSTRACT………………………………………………………………..iv
Chapter 1 .................................................................................................. 1
INTRODUCTION .................................................................................... 1
BACKGROUND ....................................................................................... 1
PROPOSED SYSTEM .............................................................................. 2
ADVANTAGES OF PROPOSED SYSTEM ............................................ 2
CHAPTER 2 ................................................................................................ 4
REQUIREMENT ANALYSIS ................................................................ 4
PROJECT IDENTIFICATION .............................................................. 4
OBJECTIVES .......................................................................................... 4
METHODOLOGY .................................................................................. 5
CHAPTER 3 ................................................................................................ 6
SYSTEM REQUIREMENT SPECIFICATION .................................... 6
HARDWARE REQUIREMENTS .......................................................... 7
SOFTWARE REQUIREMENTS ........................................................... 7
FUNCTIONAL REQUIREMENTS ....................................................... 7
NON-FUNCTIONAL REQUIREMENTS ............................................. 8
CHAPTER 4 ................................................................................................ 9
SYSTEM DESIGN .................................................................................. 9
DATAFLOW DIAGRAM ....................................................................... 9
USE CASE DIAGRAM ......................................................................... 11
ClassDiagram ......................................................................................... 13
CHAPTER 5 .............................................................................................. 14
IMPLEMENTATION ........................................................................... 14
OVERVIEW OF SYSTEM IMPLEMENTATION ............................. 14
ALGORITHM ....................................................................................... 15
PSEUDO CODE .................................................................................... 15
Chapter 6 ................................................................................................... 29
SYSTEM TESTING .............................................................................. 29
SNAPSHOTS ............................................................................................ 31
Chapter 7 ................................................................................................... 32
CONCLUSION ...................................................................................... 32
REFERENCES ...................................................................................... 32
TEXT BOOKS ....................................................................................... 32
TETRIS GAME
CHAPTER 1
INTRODUCTION
Tetris is a tile-matching puzzle video game and it is one of the most famous game in the
world. It is played on a board with 20 rows and 10 columns. There are seven shapes of
Tetriminos, and Tetriminos fall from top of the board and come to rest at the bottom
every time. The player has to control the Tetriminos by moving left and right and rotating
clockwise, and the player is needed to get the score as high as possible by clearing lines,
which is filling the horizontal row in the board.
The rules of Tetris are very simple but it is not easy to master it, like clearing more 500 of
lines. Players need to find the solution to keep the board in good shape meanwhile clear
the lines as many as possible. More lines have been cleared, the falling speed of the
Tetriminos increases, which means the difficulty increases and the player has less time to
decide the best move in the later part of the game. Therefore, the player will be prone to
make the wrong decision, and finally lose the game.
BACKGROUND
Tetris (Russian: Тéтрис [ˈtʲɛtrʲɪs]) is a tile-matching video game created by Russian software
engineer Alexey Pajitnov in 1984 for the Electronika 60 computer. It has been published by
several companies, most prominently during a dispute over the appropriation of the rights in
the late 1980s. After a significant period of publication by Nintendo, the rights reverted to
Pajitnov in 1996, who co-founded The Tetris Company with Henk Rogers to manage
licensing.
In Tetris, players complete lines by moving differently shaped pieces (tetrominoes), which
descend onto the playing field. The completed lines disappear and grant the player points,
and the player can proceed to fill the vacated spaces. The game ends when the playing field
is filled. The longer the player can delay this inevitable outcome, the higher their score will
be. In multiplayer games, the players must last longer than their opponents, and in certain
versions, players can inflict penalties on opponents by completing a significant number of
lines. Some adaptations have provided variations to the game's theme, such as three-
dimensional displays or a system for reserving pieces.Built on simple rules and requiring
intelligence and skill, Tetris established itself as one of the great early video games. The
game is available on over 65 platforms, setting a Guinness world record for the most ported
video game title. Tetris is rooted within popular culture and its popularity extends beyond the
sphere of video games; imagery from the game has influenced architecture, music
and cosplay. The game has also been the subject of various research studies that have
analyzed its theoretical complexity and have shown its effect on the human brain following a
session, in particular the Tetris effect.
PROPOSED SYSTEM
As one start the game ,he enters an arena of TETRIS .In this arena ,various shaped objects
fall with a given speed( the speed increases as one goes to a higher difficult level).The
player has to adjust these shapes in such a way that a bricked structure is
formed.Whenever a continuous line is formed ,that particular line disappears giving up
points.These blocks fall at random (one at a time).The blocks can be rotated (in just one
sense ,for example in 90 degrees or so).The speed of the block increases as the game
progreses.The game ends when the building created by these blocks touches the ceil(the
ceil is initially defined).
SCORING SYSTEM: The scoring in this game in as follows. When a single line of
brick is formed 100 points are awarded .When double line of brick is formed 300 points
are awarded .When triplet is formed 500 points are awarded and on the formation of
TETRIS 800 points are awarded . In this way the game goes on.
TYPES OF STRUCTURE:the following are the the structure we propose for the game
SQUARE
STRAIGHT ROD
OPPOSITE “L”SHAPED ROD
”L” SHAPED ROD
OPPOSITE “S” SHAPED ROD
”S”SHAPED ROD
BENDED ROD
Neuroscience of Tetris, “What this shows is that the brain actually learns how to solve
Tetris conundrums with energy efficiency while it improves performance on the same
tasks that once required loads of glucose. This is a prime example of brain efficiency.”
Prolonged bouts of play can lead to the “Tetris effect”. The term is given to someone who
plays Tetris to such an extent it becomes part of their visual day to day life: they can
dream about tetrominos (the four part geometric shapes in the game), and organize items
they see in their environment. Robert Stickgold’s research, published in 2000
by ScienceMag, noted this intriguing phenomenon, “Amnesic patients with extensive
bilateral medial temporal lobe damage produced hypnagogic reports despite being unable
to recall playing the game, suggesting that such imagery may arise without important
contribution from the declarative memory system.”
CHAPTER 2
REQUIREMENT ANALYSIS
PROJECT IDENTIFICATION
The user can install this amazing application on his/her smart phone and can get all
feature of this application. This game is played by adults and children’s as well. it is also
known as board game. Some are obvious kids enjoy them and board games are
opportunities for families to play together. In addition social scientist has argued games
teach lesson about getting along with others. Board game can teach the important social
skills.
For example Games may encourage kids to
• Consider the concept of rule
• Practice of rules
• Reason about moral problem
OBJECTIVES
The goal of Tetris is to score as many points as possible by clearing horizontal lines of
Blocks. The player must rotate, move, and drop the falling Tetriminos inside the Matrix
(playing field). Lines are cleared when they are filled with Blocks and have no empty
spaces.
As lines are cleared, the level increases and Tetriminos fall faster, making the game
progressively more challenging. If the Blocks land above the top of the playing field, the
game is over.
GOAL – Put your organizational skills and endurance to the test by clearing as many
lines as possible.
CLEAR LINES – Maneuver the falling Tetriminos to fit them together within the Matrix.
To clear a line, fill every square within a single row.
SCORE POINTS – Earn points by clearing lines. Clear multiple lines at once to increase
your scoring opportunities.
NEXT QUEUE – Preview the upcoming Tetrimino in the Next Queue to plan ahead and
increase your scoring opportunities.
GAME OVER – Stack the Tetriminos too high and the game is over!
METHODOLOGY
This project is made by using Android studio, Virtual emulator and Photoshop. The
programming languages used for building the application are Java, XML and C++. User
interface is handled using XML codes. Backend programming is handled mainly through
set of java codes. The libraries required are:
⚫ Android SDK tools
⚫ Google APIs
⚫ Google APIs ARM EABI v7a System Image
CHAPTER 3
SYSTEM REQUIREMENT SPECIFICATION
HARDWARE REQUIREMENTS
SOFTWARE REQUIREMENTS
1. Android development tool(ADT)
• Android Studio
• XML
• Java Development tool kit (JDK)
• SDK 7.0
• UML
FUNCTIONAL REQUIREMENTS
Game properties
1 Game pieces The user shall be able to control several different kinds of pieces.
2 Boundaries There shall be boundaries limiting piece movement.
3 Falling pieces The pieces shall move downwards with a given speed.
4 Score The system shall keep and display a total score.
5 Get help The user shall be able to access game instructions.
6 Menu system The user shall be able to navigate a menu system to access the different
game functions.
Game sessions
7 Start singleplayer game session The user shall be able to start a singleplayer game
session.
8 Host multiplayer game The user shall be able to host a network game.
9 Host private game The user shall be able to host a private network game.
10 Join multiplayer game The user shall be able to join a network game.
11 Chat with other users The user shall be able to chat with other users when in a game.
Piece movement
12 Move piece vertically The user shall be able to increase vertical piece movement
downwards.
13 Move piece horizontally The user shall be able to control the pieces' horizontal
movement.
14 Rotate piece The user shall be able to rotate the piece that he controls.
15 Collide with other player-controlled bricks In multiplayer sessions, different players'
pieces shall be able to collide.
Brick placement
16 Piece control The user shall control one piece at a time.
17 Fixate piece A piece that cannot move downwards shall be fixated to the board.
18 Remove row When a row is completed, it shall be removed from the game board.
19 Finishing a game session When a piece gets fixated above the top boundary, the game
session shall end.
Powerups
20 Obtain powerup The user shall be able to obtain powerups.
21 Create powerup The system shall introduce powerup bricks when rows are removed.
22 Use powerup Players shall be able to activate obtained powerups.
NON-FUNCTIONAL REQUIREMENTS
Documentation
The game shall have documentation describing the game objective, how to start a
singleplayer game session, join a session, host a session and navigate pieces. Further,
it shall explain the different powerups.
Graphics acceleration
The user shall be able to use graphics acceleration hardware for playing the game.
Inputs
The system shall support two input devices – a keyboard and the X-Box 360 game
controller.
CHAPTER 4
SYSTEM DESIGN
SYSTEM ARCHITECTURE
PS/2
50MHz Write
W/R SRAM
Keyboard Control
Control
25MHz Read
DM9000A
DM9000A Control
For a game like Tetris, the screen display dynamically changes. As game goes on, blocks
can be created as a whole and fall down as a whole but parts of them might get
eliminated. It means that lots of block data will be written dynamically into SRAM and
then output to VGA display. The clock rate of CPU and VGA are different. So there will
be a control module to monitor the read and write of SRAM. Based on these
considerations, the system structure is designed as shown in the picture.
DATAFLOW DIAGRAM
ClassDiagram
CHAPTER 5
IMPLEMENTATION
The implementation phase involves putting the project plan into action. It’s here that the
project manager will coordinate and direct project resources to meet the objectives of the
project plan. As the project unfolds, it’s the project manager’s job to direct and manage
each activity, every step of the way. That’s what happens in the implementation phase of
the project life cycle: you follow the plan you’ve put together and handle any problems
that come up.
The steps undertaken to build each deliverable will vary depending on the type of project
are undertaken, and cannot therefore be described here in any real detail. For instance
engineering and telecommunications projects will focus on using equipment, resources,
and materials to construct each project deliverable, whereas computer software projects
may require the development and implementation of software code routines to produce
each project deliverable. The activities required to build each deliverable will be clearly
specified within the project requirements document and project plan.
The Project Implementation phase has two essential functions: execution of the work and
proper delivery. The resources used in the implementation have to be accurate. Based on
the implementation, the project’s fate is decided. The success and effectiveness can only
be known after proper monitoring and feedback. This phase of delivering provides the
client with an outlook of the project. There could be many ways of implementing this
project we have chosen java because one of the most popular amongst other languages
and highly used language for developing most of the applications because the applications
that are produced by using Java are cross-platform suitable
It comes with a rich library of default design patterns and other best practices. It is more
adaptable for mobile app development because it is open-source like Spring that uses the
concept of Object-Oriented Programming. Android smartphones are now much accessible
and easy to get from the market. Here comes your idea for the execution as an innovative
mobile app that is useful for significant users that increases the rate of success.
ALGORITHM
Step 1: We have to run the code in android studio
Step 2: Click on Play Game.
Step 3: Select the Hard/Easy mode.
Step 4: The falling Tetriminos to fit them together within the Matrix. To clear a line, fill
every square within a single row.
Step 5: Earn points by clearing lines. Clear multiple lines at once to increase your scoring
opportunities.
Step 6: Stack the Tetriminos too high and the game is over!
PSEUDO CODE
Pseudo code is an informal high-level description of the operating principle of a computer
program or other algorithm. It uses the structural conventions of a programming
language, but is intended for human reading rather machine reading. Pseudocode is a
useful thing to learn because it focuses on the building block concepts of programming
languages without you having to worry about whether you are using the "right" words.
Once you've nailed the logic of coding, the rest is just filling in your pseudocode with the
syntax of a particular programming language.
GameState.java
package com.tetris.tetris;
import android.util.SparseArray;
class GameState {
boolean status;
int score;
boolean pause;
BasicBlock[][] board;
Tetramino falling;
boolean difficultMode;
private int rows;
this.rows = rows;
this.columns = columns;
this.pause = false;
ctr = 0;
score = 0;
this.status = true;
difficultMode = false;
tetraminos.put(this.ctr, falling);
}
return this.board[coordinate.y][coordinate.x];
}
returnthis.getCoordinateBlock(coordinate).state==BasicBlockState.ON_TETRAMINO;
boolean moveFallingTetraminoDown() {
}
Dept. of ISE, AMCEC 2020-2021 Page 17
TETRIS GAME
boolean moveFallingTetraminoLeft() {
boolean moveFallingTetraminoRight() {
boolean rotateFallingTetraminoAntiClock() {
if (falling.type == TetraminoType.SQUARE_SHAPED) {
return true;
} else {
for (BasicBlock block : falling.blocks) {
if (block.state == BasicBlockState.ON_EMPTY)
continue;
return false;
}
}
falling.performClockWiseRotation();
return true;
}
}
if(this.getCoordinateBlock(block.coordinate).state==BasicBlockState.ON_TETRAMINO
)
this.status = false;
}
}
void incrementScore() {
this.score++;
}
void lineRemove() {
boolean removeLines;
do {
removeLines = false;
for (int row = this.rows - 1; row >= 0; row--) {
boolean rowIsALine = true;
for (int column = 0; column < this.columns; column++) {
if (this.board[row][column].state != BasicBlockState.ON_TETRAMINO) {
rowIsALine = false;
break;
}
}
if (!rowIsALine) {
continue;
}
if (tetramino == null) {
continue;
}
this.ctr++;
Tetramino upperTetramino = tetramino.copy(this.ctr);
this.tetraminos.put(this.ctr, upperTetramino);
for (BasicBlock upperBlock : upperTetramino.blocks) {
if (upperBlock.coordinate.y >= block.coordinate.y) {
upperBlock.state = BasicBlockState.ON_EMPTY;
} else {
this.getCoordinateBlock(upperBlock.coordinate).tetraId=upperBlock.tetraId;
}
}
this.ctr++;
Tetramino lowerTetramino = tetramino.copy(this.ctr);
this.tetraminos.put(this.ctr, lowerTetramino);
for (BasicBlock lowerBlock : lowerTetramino.blocks) {
if (lowerBlock.coordinate.y <= block.coordinate.y) {
lowerBlock.state = BasicBlockState.ON_EMPTY;
} else {
this.getCoordinateBlock(lowerBlock.coordinate).tetraId=lowerBlock.tetraId;
}
}
this.tetraminos.remove(block.tetraId);
break;
}
}
}
this.adjustTheMatrix();
this.incrementScore();
removeLines = true;
break;
}
} while (removeLines);
Dept. of ISE, AMCEC 2020-2021 Page 21
TETRIS GAME
if (T != null)
this.shiftTillBottom(T);
}
}
}
CoordinatenewCoordinate=Coordinate.add(block.coordinate,newCoordinate(1, 0));
if (isTetraPresent(newCoordinate, tetramino))
continue;
if (isConflicting(newCoordinate))
shouldShiftDown = false;
}
if (shouldShiftDown) {
for (BasicBlock block : tetramino.blocks) {
Dept. of ISE, AMCEC 2020-2021 Page 22
TETRIS GAME
if (block.state == BasicBlockState.ON_EMPTY)
continue;
this.getCoordinateBlock(block.coordinate).setEmptyBlock(block.coordinate);
block.coordinate.y++;
}
this.getCoordinateBlock(block.coordinate).set(block);
}
shiftTillBottom = true;
}
} while (shiftTillBottom);
}
private boolean isTetraPresent(Coordinate coordinate, Tetramino tetramino) {
for (BasicBlock block : tetramino.blocks) {
if (block.state == BasicBlockState.ON_EMPTY)
continue;
if (Coordinate.isEqual(block.coordinate, coordinate))
return true;
}
return false;
}
MainActivity.java
package com.tetris.tetris;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
Dept. of ISE, AMCEC 2020-2021 Page 23
TETRIS GAME
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button play;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
play = findViewById(R.id.play);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, Game.class);
startActivity(intent);
}
});
Tetramino.java
package com.tetris.tetris;
import java.util.Random;
enum TetraminoType {
SQUARE_SHAPED,
T_SHAPED,
L_SHAPED,
LINE_SHAPED,
Z_SHAPED,
INV_L_SHAPED,
INV_Z_SHAPED;
class Tetramino {
BasicBlock[] blocks;
TetraminoType type;
Tetramino(TetraminoType type, int tetraId) {
Coordinate[] coordinates;
switch (type) {
case SQUARE_SHAPED:
coordinates = new Coordinate[]{
new Coordinate(0, 10),
new Coordinate(1, 10),
new Coordinate(1, 11),
new Coordinate(0, 11)
};
blocks = this.blocksGenerator(tetraId, 1, coordinates);
break;
case INV_L_SHAPED:
coordinates = new Coordinate[]{
new Coordinate(0, 10),
new Coordinate(0, 11),
new Coordinate(1, 10),
new Coordinate(2, 10)
};
blocks = this.blocksGenerator(tetraId, 2, coordinates);
break;
case L_SHAPED:
coordinates = new Coordinate[]{
new Coordinate(0, 11),
Dept. of ISE, AMCEC 2020-2021 Page 25
TETRIS GAME
void moveDown() {
Dept. of ISE, AMCEC 2020-2021 Page 27
TETRIS GAME
void moveLeft() {
for (BasicBlock block : blocks) {
block.coordinate.x--;
}
}
void moveRight() {
for (BasicBlock block : blocks) {
block.coordinate.x++;
}
}
void performClockWiseRotation() {
BasicBlock referenceBlock = blocks[0];
for (BasicBlock block : blocks) {
CoordinatebaseCoordinate=Coordinate.sub(block.coordinate,referenceBlock.coordinate);
block.coordinate=Coordinate.add(Coordinate.rotateAntiClock(baseCoordinate),reference
Block.coordinate);
}
}
}
CHAPTER 6
SYSTEM TESTING
Testing is a critical element of software quality assurance and represents the ultimate
review of specification, design, and coding- The increasing visibility of a software as a
system element and the attendant "costs" associated with a software failure are motivating
forces for well-planned, through testing. It is not unusual for the organization to spent 30
or 40 percent of total project effort on testing. In the extreme, testing of human rated
software can cost three to five times as much as all the other software engineering
activities combined! Testing presents the software an alliterating anomaly for the
software engineer.
The engineer creates the series of test cases that are intended to demolish the software
that has been built. In fact, testing is the one step in the software engineering process that
could be viewed as destructive rather than constructive. Software developers are
constructive by nature. Testing requires that developers discard preconceived notions of
the "correctness" of software just developed and overcome a conflict of interest that
occurs when the errors are uncovered. Testing objectives The following are the objectives
of testing:
1. Testing is a process of executing a program with the intention of finding an error.
2. A good test case is one that has a high probability of finding an as-yet undiscovered
error.
3. A successful test is one that uncovers as as-set undiscovered error.
Testing principles:
Before applying methods to design effective test cases, a software engineer must
understand the basic principles of testing.
They are as following:
• All tests should be traceable to customer requirements.
• Test should be planned long before testing is done.
• The Pareto principle applies to software testing.
• Testing should begin "in the small" and progress toward testing "in the large."
• Exclusive testing is not possible.
• To be most effective, independent third party should conduct testing
Testability
Software testability is simply how easily a computer program can be tested. Since testing
is profoundly difficult, it pays to know what can be done to streamline it. Sometimes
programmers are willing to do things that will help the testing process, and a checklist of
possible design points, features, and so on can be useful in negotiating with them. Here
are the set of characteristics that lead to testable software.
Operability: "the better it works, more efficiently it can be tested'
Observably: "what you see is what you test"
Controllability: "the better we can control the software, the more the testing can be
automated and optimized
Decomposability: "by controlling the scope of testing, we can more quickly isolate
problems and perform smarter retesting".
Simplicity: "the less there is test; the more quickly we can test it
Stability: "the fewer the changes, the fewer the disruption to testing"
Understandability: 'the more the information we have, the smarter we can test."
SNAPSHOTS
CHAPTER 7
CONCLUSION
Android as a full, open and free mobile device platform, with its powerful function and
good user experience rapidly developed into the most popular mobile operating system.
This report gives an overview of the different challenges and issues faced in android app
development. The experience of developing an android app is quite challenging,
motivating as well as satisfying.
Here we tried to show the brief description of Game theory. Along with this we showed
some features of game. Then we gave a brief of Artificial Intelligence along with games
and usage of AI in games. After this we explained about the gaming searches in
algorithms used mainly for the Tetris. And after all this, description of Tetris in the form
of case study is explained where the algorithm is optimized for using lesser indices so that
there is less complexity for guessing the tack number.
REFERENCES
➢ https://developer.android.com
➢ https://www.javatpoint.com
TEXT BOOKS
➢ Busy Coder’s Guide to Advanced Android Development
➢ Beginning Android 4 Games Development