0% found this document useful (0 votes)
18 views20 pages

Final Project Documentation

Uploaded by

ayesha batool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views20 pages

Final Project Documentation

Uploaded by

ayesha batool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

2048 GAME

Session 2023-2027

Submitted By:
Faiza Kiran Safdar 2023-CS-189
Ayesha Batool 2023-CS-171

Submitted To:
Sir Nazeef ul Haq

Department of Computer Science


University of Engineering and Technology Lahore
Pakistan

2048 Game Documentation Final Project


2048 GAME---------------------------------------------------------------------------------------------1

Overview of 2048--------------------------------------------------------------------------------------4

History and Origin--------------------------------------------------------------------------------------5

Summary------------------------------------------------------------------------------------------------5

Motivation----------------------------------------------------------------------------------------------5

Objectives:----------------------------------------------------------------------------------------------5

Target Audience:--------------------------------------------------------------------------------------6

Stakeholders:-------------------------------------------------------------------------------------------6

Operational Details:----------------------------------------------------------------------------------7

Use Cases:----------------------------------------------------------------------------------------------7

Wireframes---------------------------------------------------------------------------------------------8

Future Enhancements--------------------------------------------------------------------------------8

Detailed Data Structures and Algorithms:------------------------------------------------------8

AI Implementation------------------------------------------------------------------------------------9

User Interface Design--------------------------------------------------------------------------------9

Color Scheme and Typography------------------------------------------------------------10

Music and Sound Effects--------------------------------------------------------------------------10

Testing and Debugging:----------------------------------------------------------------------------10

Debugging Techniques----------------------------------------------------------------------10

Performance Optimization------------------------------------------------------------------11

How to play-------------------------------------------------------------------------------------------11

Implementation--------------------------------------------------------------------------------------11

Initial Setup------------------------------------------------------------------------------------12

Board Initialization---------------------------------------------------------------------------12

Tile Movements and Merging-------------------------------------------------------------12

Random Tile Placement---------------------------------------------------------------------12

Drawing the Board---------------------------------------------------------------------------12

Game Design-----------------------------------------------------------------------------------------12

Game Rules------------------------------------------------------------------------------------12

Technical Specifications---------------------------------------------------------------------------13

Development Environment-----------------------------------------------------------------13

2048 Game Documentation Final Project


Programming Language---------------------------------------------------------------------13

Libraries and Tools Used-------------------------------------------------------------------13

Additional Features----------------------------------------------------------------------------13

AI Bot----------------------------------------------------------------------------------------14

Undo Functionality------------------------------------------------------------------------14

Game Over Screen------------------------------------------------------------------------14

Music and Sound Effects----------------------------------------------------------------14

Blessings and Wishes---------------------------------------------------------------------14

Game Mechanics---------------------------------------------------------------------------------14

Scoring System------------------------------------------------------------------------------14

Winning and Losing Conditions---------------------------------------------------------15

User Interactions----------------------------------------------------------------------------15

Code Breakdown:--------------------------------------------------------------------------------15

Main Game Loop-----------------------------------------------------------------------------15

Event Handling--------------------------------------------------------------------------------15

Function Descriptions-----------------------------------------------------------------------16

Code Snippets and Examples--------------------------------------------------------------16

2048 Game Documentation Final Project


Overview of 2048
The 2048 game is a single-player sliding block puzzle game that involves combining
numbered tiles on a 4x4 grid to create a tile with the value of 2048. The game is
simple yet addictive, requiring strategic thinking and planning. It has gained immense
popularity due to its challenging nature and the satisfaction of achieving high scores.

History and Origin


2048 was created by Gabriele Cirulli, a 19-year-old Italian web developer, in March
2014. The game was inspired by the previously existing games "1024" and "Threes."
Within a week of its release, 2048 had garnered millions of players worldwide,
becoming a viral sensation. The game's open-source nature allowed developers to
create numerous variations and adaptations, further contributing to its widespread
popularity.

Summary
The 2048 game is a single-player sliding block puzzle game that involves combining
numbered tiles on a 4x4 grid to create a tile with the value of 2048. The game is
simple yet addictive, requiring strategic thinking and planning. It has gained immense
popularity due to its challenging nature and the satisfaction of achieving high
scores.The 2048 game is a single-player sliding block puzzle game that challenges
players' strategic thinking and problem-solving skills. Developed using Python and
the Pygame library, this project incorporates various data structures such as lists,
dictionaries, sets, stacks, queues, graphs, and linked lists to enhance gameplay and
functionality. The goal is to demonstrate the practical applications of these data
structures in a real-world scenario while providing an engaging and educational
experience for players and developers alike.

Motivation
The primary motivation behind this project is to explore the practical applications of
data structures in game development. By integrating different data structures into the

2048 Game Documentation Final Project


2048 game, we aim to showcase their importance and utility in managing game logic,
optimizing performance, and enhancing user experience. This project also serves as a
platform for students and developers to improve their coding skills, problem-solving
abilities, and understanding of algorithms.

Objectives:
Develop a fully functional 2048 game:

Create a working version of the 2048 game using Python and Pygame.

Incorporate various data structures:

Utilize lists, dictionaries, sets, stacks, queues, graphs, and linked lists to manage
game logic, AI, and additional features.

Enhance user experience:

Implement features such as undo functionality, AI moves, continuous background


music, and a game over screen with blessings or wishes.

Demonstrate practical applications:

Showcase how different data structures can be effectively used in game development
to manage complexity and improve performance.

Target Audience:
Students and educators:

The project serves as an educational tool to demonstrate the application of data


structures in a practical scenario.

Game developers:

Gain insights into integrating data structures into game logic and enhancing user
experience.

Enthusiasts:

Improve coding skills and explore advanced game development techniques.

Stakeholders:
Students:

2048 Game Documentation Final Project


Gain practical experience and understanding of data structures and algorithms
through hands-on coding.

Educators:

Use the project as a teaching tool to explain the importance of data structures in real-
world applications.

Game developers:

Learn how to incorporate data structures into game logic and design to create a more
engaging user experience.

Enthusiasts:

Enhance coding skills and explore new approaches to game development.

Operational Details:
Development Environment:

The game will be developed using Python 3.x and the Pygame library. Pygame
provides the necessary tools for handling graphics, sounds, and user input.

Code Repository:

A version control system like GitHub will be used to manage the codebase and
collaborate with other developers.

Music and Sound Effects:

Background music and sound effects will be added using Pygame's mixer module.
The music will be sourced from the "dsa" folder and will play continuously during the
game. The music will stop when the game quits.

Game Assets:

Custom graphics for tiles, buttons, and backgrounds will be created to enhance the
visual appeal of the game.

Use Cases:
Start Game:

The player initiates a new game by clicking the "New Game" button, which resets the
board and score.

Move Tiles:

2048 Game Documentation Final Project


The player uses arrow keys to slide tiles in the desired direction, combining tiles of
the same value.

Undo Move:

The player can revert to the previous game state by clicking the "Undo" button.

AI Move: The player can ask the AI to make an optimal move by clicking the "AI
Move" button.

Game Over:

When no more moves are possible, a game over screen is displayed with 45 blessings
or wishes and a "Congratulations" message.

Wireframes

2048 Game Documentation Final Project


Figure1:Game Start Window

2048 Game Documentation Final Project


Figure2:Game Start Working

Figure3:Game Playing

2048 Game Documentation Final Project


Figure4: Tiles Fill

Figure5:Game Over Window

2048 Game Documentation Final Project


Figure6:New Game Start Window

Figure7:Score Board

2048 Game Documentation Final Project


Detailed Data Structures and Algorithms:
Lists:

Used to represent the game board as a 2D grid (4x4 list).

Stores tile values and facilitates tile movements and merging.

Each cell contains a tile value.

Dictionaries

Used to map tile values to their respective colors for rendering.

Sets

Used to keep track of visited states in the AI implementation.

Ensures that the AI does not revisit the same state, optimizing move selection.

Stacks

Used to implement the undo functionality.

Stores previous game states, allowing players to revert to a previous state.

Queues

Used in the AI implementation for breadth-first search (BFS) to find the optimal
moves.

Graphs

Represent possible moves and paths in the AI to determine the best move sequence.

Linked Lists

Used to store and display the move history, allowing players to track their actions.

Sorting and Searching

Algorithms implemented for features like sorting scores or searching through the
move history for specific actions.

AI Implementation
AI Algorithm

2048 Game Documentation Final Project


The AI uses a combination of heuristics and search algorithms to determine the
optimal move. It evaluates the board state, possible moves, and their outcomes to
select the move that maximizes the score and minimizes the risk of losing.

User Interface Design

Color Scheme and Typography

Background Color: RGB(187, 173, 160)

Empty Tile Color: RGB(205, 193, 180)

Tile Colors: Vary based on the tile value, with higher values having more intense
colors.

Text Color: RGB(119, 110, 101)

Fonts: Default Pygame font with a font size of 55 for tiles and 36 for buttons,
ensuring readability and clarity.

Music and Sound Effects

Continuous Background Music

Background music is played continuously during the game to enhance the player's
experience. The music is sourced from the "dsa" folder and is managed using
Pygame's mixer module

The music stops automatically when the game is quit.

Sound Effects

Sound effects are played for actions such as merging tiles, starting a new game, and
achieving a new high score.

Testing and Debugging:


Test Cases

Various test cases are designed to ensure the game functions correctly. These include
tests for tile movements, merging behavior, score calculation, and game over

2048 Game Documentation Final Project


conditions.Test cases are designed to validate the game's functionality and ensure it
behaves as expected.

Includes tests for tile movements, merging, score calculation, and AI moves.

Debugging Techniques

Debugging tools and techniques are used to identify and fix issues in the code.

Includes print statements, breakpoints, and code analysis.

Performance Optimization

Techniques are implemented to optimize the game's performance.

Includes efficient data structures, algorithms, and minimizing redundant calculations

How to play
This is a tile-sliding game. It means, it has is a board-game which has numbers on
tiles. We slide the tiles and merge the numbers. We can only slide the tiles to Up,
Down, Left, and Right directions. Choosing a direction will mean every element on
the board will move to that direction.

Only two same numbers will merge; for example, we can merge 2 and 2, but we
cannot merge 2 and 4. The goal is to merge the numbers until we get 2048. Merging
numbers to 2048 will mean we have won the game. Otherwise, if there are no empty
tiles left and we cannot merge any more numbers, the game is over and we lose.

At the beginning of the game, two 2's are randomly generated to start the game. As
we swipe from left to right or any other direction, with every move a random number
2 or 4 is added to board. This addition of random number happens whether the other
tiles are merged or not.

Implementation
We will be explaining the steps as we implement the code. For this game, we have
chosen a 4X4 matrix; that would be a square board with 4 rows and 4 columns.

2048 Game Documentation Final Project


To show the board and get the similar experience of actually playing the game, we are
using the standard GUI library Tkinter for the graphical interface. It provides widgets
that can be easily implemented as needed. We are also importing the random library
to generate random numbers.

"Frame" widget in Tkinter keeps other widgets organized and working together. The
colors for the board and the tiles are randomly picked and methods are defined for
every function of the game.

Initial Setup

The initial setup involves importing necessary libraries, defining constants for colors,
fonts, and tile sizes, and initializing the Pygame environment. The game window is
created with specified dimensions, and fonts are loaded for rendering text.

Board Initialization

The game board is represented as a 2D list (4x4 grid), initialized with zeros. Two
random tiles with values of 2 or 4 are placed on the board to start the game.

Tile Movements and Merging

Tiles can be moved in four directions: left, right, up, and down. Functions are
implemented to handle tile sliding and merging. When two tiles of the same value
collide, they merge into a single tile with the combined value.

Random Tile Placement

After each move, a new tile with a value of 2 or 4 is placed in an empty spot on the
board. The place_random_tile() function ensures that the new tile appears in a
random empty cell.

Drawing the Board

2048 Game Documentation Final Project


The draw_board() function is responsible for rendering the game board and tiles on
the screen. It uses Pygame's drawing functions to display tiles with appropriate colors
and values, as well as the current score and messages.

Game Design

Game Rules

The game is played on a 4x4 grid.

Each turn, a new tile (with a value of 2 or 4) appears in an empty spot on the board.

Tiles slide as far as possible in the chosen direction until they are stopped by another
tile or the edge of the grid.

If two tiles of the same number collide while moving, they merge into a tile with the
total value of the two tiles that collided.

The game is won when a tile with the value of 2048 appears on the board. Players can
continue playing to reach higher scores.

The game is over when no more moves are possible.

Technical Specifications

Development Environment

The 2048 game is developed using Python 3.x and the Pygame library, a set of Python
modules designed for writing video games.

Programming Language

Python: Chosen for its simplicity, readability, and extensive library support. Python
allows for rapid development and prototyping, making it an ideal choice for game
development.

Libraries and Tools Used

2048 Game Documentation Final Project


Pygame: A cross-platform set of Python modules designed for writing video games.
It provides functionalities for creating graphics, handling user input, and playing
sounds.

Other Tools: Git for version control and collaboration.

Additional Features

AI Bot

An AI bot is implemented to make optimal moves on behalf of the player.

Uses algorithms like BFS to evaluate possible moves and select the best one.

Undo Functionality

Allows players to revert to a previous game state.

Enhances the user experience by providing a way to correct mistakes.

Game Over Screen

Displays a "Game Over" message when no more moves are possible.

Includes 45 blessings or wishes and a "Congratulations" message to encourage and


motivate players.

Music and Sound Effects

Background music sourced from the "dsa" folder plays continuously during the game.

Music stops when the game quits.

Sound effects are added for tile movements and merges to enhance the gaming
experience.

Blessings and Wishes

2048 Game Documentation Final Project


A list of 45 blessings or wishes is displayed on the game over screen.

Provides positive reinforcement and encouragement to players.

Game Mechanics

Scoring System

The score increases whenever tiles are merged.

The merged tile's value is added to the score.

The current score is displayed at the top of the game screen.

Winning and Losing Conditions

The game is won when a tile with the value of 2048 appears on the board.

The game continues to allow players to reach higher scores.

The game is over when no more moves are possible.

User Interactions

Players use arrow keys to move tiles in the desired direction.

Buttons are provided for starting a new game, undoing the last move, and invoking
the AI to make a move.

Visual and audio feedback enhances user interactions and provides a satisfying
gaming experience.

Code Breakdown:

Main Game Loop

The main game loop handles the game's logic, updating the game state, and rendering
the game board.

2048 Game Documentation Final Project


It processes user inputs, updates the board, and checks for win/loss conditions.

Event Handling

Handles user inputs such as key presses and button clicks.

Updates the game state based on user interactions.

Function Descriptions

Each function is documented with a description of its purpose, parameters, and return
values.

Clear and concise descriptions help in understanding the code and its functionality.

Code Snippets and Examples

Relevant code snippets are provided to illustrate key functionalities.

Examples demonstrate how different data structures and algorithms are implemented
in the game.

Future Enhancements
Multiplayer Mode:

Implementing a multiplayer mode where players can compete against each other on
separate boards or on the same board in turn-based gameplay.

Power-Ups and Boosters:

Introducing power-ups that provide special abilities, such as merging multiple tiles at
once or doubling the value of a tile.

Leaderboards:

Adding online leaderboards to display high scores and allow players to compete
globally.

Achievements and Rewards:

2048 Game Documentation Final Project


Incorporating a system of achievements and rewards to motivate players and provide
a sense of accomplishment.

Customizable Themes:

Allowing players to customize the appearance of the game, including tile colors,
backgrounds, and fonts.

2048 Game Documentation Final Project

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy