Mini Project
Mini Project
Mini Project
On
“ 2048 GAME ”
Submitted By:
Mr. Aniruddha A Bhimte
Certificate
1
“ 2048 GAME ”
Abstract:
The 2048 game involves tiles labeled with powers of two that can be merged to
form bigger powers of two; variants of the same puzzle involve similar merges of
other tile values. We analyze the maximum score achievable in these games by
proving a min-max theorem equating this maximum score (in an abstract
generalized variation of 2048 that allows all the moves of the original game) with
the minimum value that causes a greedy change-making algorithm to use a given
number of coins. A widely-followed strategy in 2048 maintains tiles that represent
the move number in binary notation, and a similar strategy in the Fibonacci number
variant of the game (987) maintains the Zeckendorf representation of the move
number as a sum of the fewest possible Fibonacci numbers; our analysis shows that
the ability to follow these strategies is intimately connected with the fact that
greedy change-making is optimal for binary and Fibonacci coinage. For variants of
2048 using tile values for which greedy change-making is suboptimal, it is the
greedy strategy, not the optimal representation as sums of tile values, that controls
the length of the game. In particular, the game will always terminate whenever the
sequence of allowable tile values has arbitrarily large gaps between consecutive
values.
Description of Project:
Ever since civilisation has begun, humans have continuously looked for new
methods of Fun and entertainment,such as art,dance,music,sports. Board Games
and puzzles like Chess, Ludo, Snake n Ladders have been present since ancient
days,The history of chess goes back almost 1500 years. These games were
fulfilling not only our need of entertainment,but also helped in having a sharp
brain. We as humans enjoy being challenged and loved to solve them. However,
with the advancement in technology,these board games are now replaced with
mobile apps and PC Games. These games make use of highly-efficent software and
2
“ 2048 GAME ”
very creative visual effects and user-interface for the user to like it. Games such as
angry bird, temple run, subway surfer, candy crush are some popular examples of
these games which became an instant hit among the users. Unlike Call of Duty,
PUBG which are much more complicated and require higher storage and better
processers, these smaller games are easier to understand yet intresting to play. Also
due to their lesser technical requirements, they can be used efficently on even a
older device. 2048 is one such classic mind-sharpening game that tests your
mathematical aptitute, skills and reflexes.It has gained world-wide pubicity and
popularity in a very short span of time. The main objective of the game is to add
tiles having same number and get a higher value of total sum. With each move a
new tile is added to the board, randomly at any vacant space. The game is designed
in such a way that it becomes progressively difficult and intresting. More the
moves you make, more the tiles are added which increases you total score but at
the same time gives you less space and in this way the game becomes difficult. The
game comes in different modes and board sizes If you are a type of person who
likes to challenge themselves with puzzles and mind games, then 2048 will surely
amaze you.
How to play 2048 :
1. There is a 4*4 grid which can be filled with any number. Initially two random
cells are filled with 2 in it. Rest cells are empty.
2. We have to press any one of four keys to move up, down, left, or right. When we
press any key, the elements of the cell move in that direction such that if any two
identical numbers are contained in that particular row (in case of moving left or
right) or column (in case of moving up and down) they get add up and extreme cell
in that direction fill itself with that number and rest cells goes empty again.
3. After this grid compression any random empty cell gets itself filled with 2.
4. Following the above process we have to double the elements by adding up and
make 2048 in any of the cell. If we are able to do that we wins.
3
“ 2048 GAME ”
Motivation/Problem statement:
Methodology:
The main objective of the project is to create a presentable, nice functioning, user
experience friendly game. To achieve this we have made use tkinter library, numpy
and matplotlib packages. Tkinter library is responsible for the user interface of the
game, it lays down the grid, tiles in a well-organised manner. Numpy and
Matplotlib provide us the backbone of our logic used in the game. All the game
functions i.e adding of two tiles,generataing a new tile at any random vacant space
4
“ 2048 GAME ”
etc. are executed only due to presence of numpy and matplotlib library. The
combination of these software in our code gives us a proper output of 2048 game
which not only has great user interface but also is equally challenging and
intresting to play.
System Architrchture :-
5
“ 2048 GAME ”
● Data Collection –
Data collection module is an integral part of our 2048 game, it includes data
collection, data interpretation and understanding the data which helps in prediction of
next moves by the compiler and evaluating the results.
● Data preprocessing –
In this project the moves made by the user leads to more tiles being generated
along with tiles with higher values(128,256,512,1024,2048 etc). All this game data are
collected during runtime besides some data(such as grid layout,initial tiles) being already
pre-processed. Thus pre-processing helps transform data so that a better gaming
experience can be provided, providing higher accuracy. The pre-processing performs
various functions:Adding tiles after a move, filling missing tiles, Updating total score,
Updating high-score.
In this, the collected data is put to use by the compiler, as the game progresses, more tiles
are added and vacant tile spaces are reduced. therefore the compiler needs to implement
the previously collected data to progress the game further. `
Also, the score needs to be updated after each move and it should also update the high
score if needed.
Initial game layout with only 2 tiles Adding of same tiles Updating current score
Updating High score if needed.
The attributes used in this project are game controls, insertion of new tiles, updating the
score etc. These attributes will be used for the prediction of next moves by the compiler.
To achieve this we have made use of the tkinter library, numpy and matplotlib packages.
Tkinter library is responsible for the user interface of the game, it lays down the grid tiles
in a well-organised manner. Numpy and Matplotlib provide us with the backbone of our
logic used in the game. All the game functions i.e adding of two tiles, generating a new
6
“ 2048 GAME ”
tile at any random vacant space etc. are executed only due to presence of numpy and
matplotlib library
Tools Used:
SOFTWARE REQUIREMENT
a) SOFTWARE : Python 3
b) IDE’s / FRAMEWORKS : VS Code
c) LIBRARIES : Tkinter, Matplotlib, Numpy.
d) Platform : Windows
1) Python :
Python is an interpreted, object-oriented, high-level programming language with dynamic
semantics. Its high-level built in data structures, combined with dynamic typing and
dynamic binding, make it very attractive for Rapid Application Development, as well as
for use as a scripting or glue language to connect existing components together. Python's
simple, easy to learn syntax emphasizes readability and therefore reduces the cost of
program maintenance. Python supports modules and packages, which encourages
program modularity and code reuse. The Python interpreter and the extensive standard
library are available in source or binary form without charge for all major platforms, and
can be freely distributed. Often, programmers fall in love with Python because of the
increased productivity it provides. Since there is no compilation step, the edit-test-debug
cycle is incredibly fast. Debugging Python programs is easy: a bug or bad input will
never cause a segmentation fault. Instead, when the interpreter discovers an error, it raises
an exception. When the program doesn't catch the exception, the interpreter prints a stack
trace. A source level debugger allows inspection of local and global variables, evaluation
of arbitrary expressions, setting breakpoints, stepping through the code a line at a time,
and so on. The debugger is written in Python itself, testifying to Python's introspective
power. On the other hand, often the quickest way to debug a program is to add a few print
statements to the source: the fast edit-test-debug cycle makes this simple approach very
effective.
7
“ 2048 GAME ”
2) VS Code:
Visual Studio Code combines the simplicity of a source code editor with powerful
developer tooling, like IntelliSense code completion and debugging. First and foremost, it
is an editor that gets out of your way. The delightfully frictionless edit-build-debug cycle
means less time fiddling with your environment, and more time executing on your ideas.
At its heart, Visual Studio Code features a lightning fast source code editor, perfect for
day-to-day use. With support for hundreds of languages, VS Code helps you be instantly
productive with syntax highlighting, bracket-matching, autoindentation, box-selection,
snippets, and more. Intuitive keyboard shortcuts, easy customization and
community-contributed keyboard shortcut mappings let you navigate your code with
ease. For serious coding, you'll often benefit from tools with more code understanding
than just blocks of text. Visual Studio Code includes built-in support for IntelliSense code
completion, rich semantic code understanding and navigation, and code refactoring. And
when the coding gets tough, the tough get debugging. Debugging is often the one feature
that developers miss most in a leaner coding experience, so we made it happen. Visual
Studio Code includes an interactive debugger, so you can step through source code,
inspect variables, view call stacks, and execute commands in the console. VS Code also
integrates with build and scripting tools to perform common tasks making everyday
workflows faster. VS Code has support for Git so you can work with source control
without leaving the editor including viewing pending changes diffs.
3) Tkiner :
Python Tkinter Tutorial Python Tkinter Tutorial Tkinter tutorial provides basic and
advanced concepts of Python Tkinter. Our Tkinter tutorial is designed for beginners and
professionals. Python provides the standard library Tkinter for creating the graphical user
interface for desktop based applications. Developing desktop based applications with
python Tkinter is not a complex task. An empty Tkinter top-level window can be created
by using the following steps.
● import the Tkinter module.
● Create the main application window.
● Add the widgets like labels, buttons, frames, etc. to the window. 7
● Call the main event loop so that the actions can take place on the user's
computer screen.
8
“ 2048 GAME ”
4) Numpy :
NumPy is a Python library used for working with arrays. It also has functions for working
in domain of linear algebra, fourier transform, and matrices. NumPy was created in 2005
by Travis Oliphant. It is an open source project and you can use it freely. NumPy stands
for Numerical Python. In Python we have lists that serve the purpose of arrays, but they
are slow to process. NumPy aims to provide an array object that is up to 50x faster than
traditional Python lists. The array object in NumPy is called ndarray, it provides a lot of
supporting functions that make working with ndarray very easy. Arrays are very
frequently used in data science, where speed and resources are very important.
5) Matplotlib:
Matplotlib is a comprehensive library for creating static, animated, and interactive
visualizations in Python. Matplotlib makes easy things easy and hard things possible.
• Create publication quality plots.
• Make interactive figures that can zoom, pan, update.
• Customize visual style and layout.
• Export to many file formats.
• Embed in JupyterLab and Graphical User Interfaces.
• Use a rich array of third-party packages built on Matplotlib
6) Windows
Windows is a graphical operating system developed by Microsoft. It allows users to view
and store files, run the software, play games, watch videos, and provides a way to
connect to the internet. It was released for both home computing and professional work.
Microsoft introduced the first version as 1.0 It was released for both home computing and
professional functions of Windows on 10 November 1983. Later, it was released on many
versions of Windows as well as the current version, Windows 11.
9
“ 2048 GAME ”
Output Screenshots
Start of Game
10
“ 2048 GAME ”
11
“ 2048 GAME ”
12
“ 2048 GAME ”
13
“ 2048 GAME ”
APPLICATION :-
The purpose of our project was to create a user-friendly gaming experience. By using the latest
software we have achieved the project objective. 2048 game can be played by any age group
from 6 to 40 as the only requirement to play the game is that the user should know basic maths
(addition). This feature makes this game a simple yet efficent and entertaining way of having
fun. Plus it can also be used as an educational tool for children of younger age group as it makes
learning fun. The colored graphics and and excellent user interface makes it easy to play and
great pastime activity. This game is equally challenging at same time which makes it a good pick
for the older age group of audience. So to summarize, our project has the following real life
applications:
● A great source of entertainment and fun
● A good tool to challenge your brain and test your mathematical aptitude
● Can be used as an educational tool to teach children addition in a fun way.
Conclusion:
We have successfully created a 2048 game.The main objective of the project was to create a
presentable, nice functioning, user experience friendly game. To achieve this we made use of
tkinter library, numpy and matplotlib packages. Tkinter library is responsible for the user
interface of the game, it lays down the grid, tiles in a well-organised manner. Numpy and
Matplotlib provide us the backbone of our logic used in the game. All the game functions i.e
adding of two tiles,generataing a new tile at any random vacant space etc. are executed only due
to presence of numpy and matplotlib library. The combination of these software in our code
gives us a proper output of 2048 game Overall while playing the game we have not faced any
issue in the functioning of the code. The game runs smoothly, the user interface is nice and
responsive which gives a good experience. The game fuctions work in a proper efficent manner
and overall its lot of fun to play.
● In the end we can draw following conclusions from our project work:
● All libraries, modules are successfully imported in our system.
● These libraries make functions of our project easier and glitch free.
● All game functions defined for game moves, score updation, new tile addition work
perfectly.
● The user interface looks good and controls are easy to learn and user-friendly.
14
“ 2048 GAME ”
SOURCE CODE :-
● game.py
15
“ 2048 GAME ”
16
“ 2048 GAME ”
17
“ 2048 GAME ”
● Game_display.py
18
“ 2048 GAME ”
19
“ 2048 GAME ”
20
“ 2048 GAME ”
21
“ 2048 GAME ”
● Game_functions.py
22
“ 2048 GAME ”
23
“ 2048 GAME ”
24
“ 2048 GAME ”
25
“ 2048 GAME ”
References:
https://www.youtube.com/watch?v=rTpnyb3y5-w
26