0% found this document useful (0 votes)
9 views21 pages

SPL1 Template

The SPL-1 Project Report details the development of 'Chor-Dakat-Police-Babu', a role-based strategy game that utilizes Markov chains for dynamic role assignment and merge sort for leaderboard ranking. Implemented in C++ with SFML for graphics, the project showcases advanced algorithms in a real-time gaming environment. Key features include a client-server architecture, interactive gameplay, and a user-friendly interface, all aimed at providing an engaging gaming experience.

Uploaded by

bsse1531
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)
9 views21 pages

SPL1 Template

The SPL-1 Project Report details the development of 'Chor-Dakat-Police-Babu', a role-based strategy game that utilizes Markov chains for dynamic role assignment and merge sort for leaderboard ranking. Implemented in C++ with SFML for graphics, the project showcases advanced algorithms in a real-time gaming environment. Key features include a client-server architecture, interactive gameplay, and a user-friendly interface, all aimed at providing an engaging gaming experience.

Uploaded by

bsse1531
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/ 21

SPL-1 Project Report

[Chor-Dakat-Police-Babu]

Submitted by

[Fahim Shahryer Sizan ]


BSSE Roll No. : 1531
BSSE Session: 2022-2023

Submitted to

[Professor Mohammed Shafiul Alam


Khan]

Institute of Information Technology,

University of Dhaka

[25-03-2025]
Signature:

Table of Contents

1. Introduction
2. Background of the Project
2.1 Role-Based Games
2.2 Markov Chains in Game Design
2.3 Sorting Algorithms in Game Development
3. Description of the Project
3.1 System Architecture
3.2 Key Features
3.3 Game Flow
4. Implementation and Testing
4.1 Implementation Details
4.2 Testing Details
5. User Interface
6. Challenges Faced
7. Conclusion
8. References
9. Appendix
1. Introduction
Chor-Dakat-Police-Babu is a role-based strategy game where players
are assigned unique roles (Police, Chor, Dakat, Babu) and compete to
achieve their objectives. The game is designed to simulate a dynamic and
unpredictable environment using Markov chains for role assignment and
merge sort for leaderboard ranking. The project aims to provide an
engaging and strategic gaming experience while demonstrating the
application of advanced algorithms in game development.

The game is implemented using C++ and SFML (Simple and Fast
Multimedia Library) for graphics and user interaction. The project
showcases the use of stochastic models and efficient sorting
algorithms in real-time applications

2.Background of the Project


2.1 Role-Based Games

Role-based games are a popular genre where players assume specific


roles with unique abilities and objectives. These games often involve
strategy, teamwork, and deception, making them highly engaging.
Examples include Mafia, Werewolf, and Among Us.

2.2 Markov Chains in Game Design

A Markov chain is a stochastic model that describes a sequence of


possible events, where the probability of each event depends only on the
state attained in the previous event. In this game, Markov chains are used
to assign roles dynamically, ensuring unpredictability and fairness.

2.3 Sorting Algorithms in Game Development

Sorting algorithms are essential for organizing data efficiently. In this


project, merge sort is used to rank players on the leaderboard based on
their scores. Merge sort is chosen for its efficiency (O(n log n)) and
stability.
2.4 Real-Time Game Mechanics

Real-time games require efficient handling of user inputs, game state


updates, and rendering. This project uses SFML to manage real-time
updates and provide a smooth user experience.

3. Description of the Project


3.1 System Architecture

The game follows a client-server architecture where the server handles


role assignment, scoring, and leaderboard management, while the client
provides the user interface for gameplay.

3.1.1 Server Component

 Role Assignment: Uses Markov chains to assign roles dynamically.


 Scoring System: Tracks player scores based on game outcomes.
 Leaderboard Management: Uses merge sort to rank players.

3.1.2 Client Component

 User Interface: Displays roles, scores, and game progress.


 Game Logic: Handles player interactions and role-specific actions.

3.2 Key Features

 Dynamic Role Assignment: Ensures unpredictability using Markov


chains.
 Leaderboard Ranking: Uses merge sort to rank players efficiently.
 Interactive Gameplay: Provides a user-friendly interface for players.

3.3 Game Flow

1. Role Assignment: Roles are assigned using a Markov chain.


2. Gameplay: Players perform role-specific actions.
3. Scoring: Scores are calculated based on game outcomes.
4. Leaderboard: Players are ranked using merge sort.
4. Implementation and Testing
4.1 Implementation Details

4.1.1 Markov Chain for Role Assignment


The Markov chain is implemented using a transition matrix
that determines the probability of assigning each role.
4.1.2 Merge Sort for Leaderboard Ranking
4.1.2 Merge Sort for Leaderboard Ranking
4.1.3 Game Interface

The game interface is implemented using SFML (Simple and


Fast Multimedia Library).
1. Scoring Rules

The scoring system is based on the following rules:

 Police:
o If the Police correctly guesses the Chor & Dakat they

earn 80 points.

o If the Police guesses incorrectly, they earn 0 points,


and the Chor and Dakat earn their respective points.

 Chor (Thief):
o If the Police guesses incorrectly, the Chor earns 40

points.

o If the Police guesses correctly, the Chor earns 0


points.

 Dakat (Bandit):
o If the Police guesses incorrectly, the Dakat earns 60

points.

o If the Police guesses correctly, the Dakat earns 0


points.

 Babu (Neutral Role):


o The Babu does not directly influence the scoring

system but may earn points indirectly based on game


outcomes.

2. Score Calculation Logic

The score calculation is implemented as follows:


1. Role Assignment: Roles are assigned dynamically using a
Markov chain.

2. Police Guess: If the player is the Police, they guess the


identity of the Chor.

3. Outcome Resolution:
o If the Police guesses correctly:

 Police earns 80 points.

 Chor and Dakat earn 0 points.

o If the Police guesses incorrectly:


 Chor earns 40 points.

 Dakat earns 60 points.

 Police earns 0 points.

4. Score Update: Scores are updated dynamically after each


round.
3. Implementation:The score calculation is implemented in
the CalculationPoints() function:

4. Testing

The scoring system was tested for:

 Correct Police Guess: Verified that the Police earns 80


points, and the Chor and Dakat earn 0 points.
 Incorrect Police Guess: Verified that the Chor earns 40
points, the Dakat earns 60 points, and the Police earns 0
points.

 Edge Cases: Tested scenarios where roles are reassigned


or players have tied scores.

5. Importance of Score Calculation

 Encourages Strategy: Players must strategize based on


their roles to maximize their scores.

 Ensures Fairness: The scoring system rewards players


fairly based on their performance.

 Drives Competition: The leaderboard, updated using


merge sort, ranks players based on their scores, adding a
competitive element to the game

SFML Graphics Code:


1. Server-Client Architecture

 Server:
o Acts as the central authority.
o Handles role assignment, score calculation, and
leaderboard updates.

o Broadcasts game state updates to all connected


clients.

 Clients:
o Players connect to the server via LAN.

o Send inputs (e.g., Police guesses) to the server.

o Receive game state updates (e.g., roles, scores) from


the server.

2. Key Components

1. Socket Programming:
o The server and clients communicate using TCP/IP

sockets.

o The server listens for incoming connections on a


specific IP address and port.

o Clients connect to the server using the server's LAN


IP address and port.

2. Game Logic on Server:


o Role assignment using Markov chains.

o Score calculation based on game outcomes.

o Leaderboard management using merge sort.

3. Real-Time Updates:
o The server broadcasts game state updates (e.g., roles,

scores, round results) to all clients in real-time.


3. Implementation Steps

1. Server Setup:
o Create a server socket and bind it to a LAN IP address

and port.

o Listen for incoming client connections.

Client Connection:
 Clients connect to the server using the server's LAN IP address and
port.
1. Role Assignment:
o The server assigns roles to players using a Markov

chain and sends the roles to clients.

2. Gameplay:
o Clients send inputs (e.g., Police guesses) to the server.

o The server calculates scores and updates the game


state.

3. Broadcasting Updates:
o The server broadcasts updates (e.g., scores, round

results) to all clients.

4. Leaderboard Updates:
o The server sorts players using merge sort and sends the
updated leaderboard to clients.
4. Advantages of LAN Implementation

 Low Latency: LAN provides fast communication between


the server and clients, ensuring real-time gameplay.

 Security: LAN is a private network, reducing the risk of


external attacks.

 Scalability: The server can handle multiple clients within


the LAN, making it suitable for small to medium-sized
groups.

5. Example Workflow
1. Server: Starts and waits for client connections.

2. Clients: Connect to the server and send player names.

3. Server: Assigns roles and sends them to clients.

4. Clients: Play the game and send inputs to the server.

5. Server: Calculates scores, updates the leaderboard, and broadcasts


results.

6. Clients: Display updated game state and leaderboard.

Challenges Faced
1. Markov Chain Implementation
 Challenge: Ensuring fair and unpredictable role assignment.

 Solution: Used a transition matrix to define probabilities for role


assignment. This ensured that roles were assigned dynamically and
fairly, avoiding repetitive patterns.

2. Merge Sort Optimization

 Challenge: Efficiently sorting large datasets for the leaderboard.

 Solution: Implemented merge sort, which has a time complexity


of O(n log n), ensuring fast and efficient sorting even with a large
number of players.

3. Real-Time Game Updates

 Challenge: Managing real-time interactions and updates between


the server and clients.

 Solution: Leveraged SFML's event-driven architecture to handle


real-time updates, ensuring smooth and responsive gameplay.

4. User Interface Design

 Challenge: Creating an intuitive and visually appealing user


interface.

 Solution: Utilized SFML's graphics and text rendering


capabilities to design a user-friendly interface with buttons, text
boxes, and dynamic updates.

5. Server Implementation Challenges

 Challenge 1: Handling Multiple Clients


o Issue: Managing multiple client connections simultaneously
without performance degradation.

o Solution: Used multi-threading to handle each client


connection in a separate thread, ensuring the server remains
responsive.
 Challenge 2: Synchronization
o Issue: Ensuring all clients receive game state updates
simultaneously to maintain consistency.

o Solution: Implemented a broadcasting mechanism where


the server sends updates to all connected clients at once.

 Challenge 3: Connection Management


o Issue: Detecting and handling client disconnections
gracefully.

o Solution: Added a heartbeat mechanism to periodically


check client connections and remove disconnected clients.

 Challenge 4: Scalability
o Issue: Scaling the server to support a larger number of
players.

o Solution: Optimized server performance by reducing


redundant computations and using efficient data structures.

Conclusion
The Chor-Dakat-Police-Babu project successfully demonstrates the
integration of advanced algorithms (Markov chains, merge sort) and
real-time networking (LAN-based server-client architecture) in game
development. The game provides an engaging and strategic experience,
showcasing the importance of efficient algorithms and robust server-
client communication. Key achievements include:

 Fair and unpredictable role assignment using Markov chains.


 Efficient leaderboard ranking using merge sort.

 Real-time gameplay and updates using SFML and LAN.

 A user-friendly interface for seamless interaction.

The project highlights the practical application of theoretical concepts in


a real-world scenario, making it a valuable learning experience.

References
1. SFML Documentation:
https://www.sfml-dev.org/documentation/2.5.1/
o Official documentation for SFML, used for graphics, window
management, and event handling.
2. Markov Chains:
GeeksforGeeks (2023). "Markov Chains."
https://www.geeksforgeeks.org/markov-chains/
o Explanation of Markov chains and their applications.

3. Merge Sort Algorithm:


Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C.
(2022). Introduction to Algorithms. MIT Press.
o Comprehensive guide to sorting algorithms, including merge
sort.

4. Socket Programming:
Beej's Guide to Network Programming.
https://beej.us/guide/bgnet/
o Detailed guide on socket programming for LAN-based
communication.

Appendix
SFML Data
 Window Size: 800x600 pixels.

 Font Used: Arial (loaded from arial.ttf).

 Game Title: "Chor-Dakat-Police-Babu".

 UI Elements:
o Buttons: Single Player, 16 Rounds, 20 Rounds, 24 Rounds.

o Text Box: For player name input.

o Leaderboard: Displays player scores.

LAN Data

 Server IP: 192.168.1.100 (example LAN IP).

 Port: 8080.

 Max Clients: 4.

 Broadcasting: The server sends game state updates (e.g., roles,


scores) to all connected clients.

You might also like