Chess CPP SE Document

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 33

CENTRAL UNIVERSITY OF HARYANA

Practical File
On
Software Engineering Lab (BT CS 606A)

Submitted To: Submitted By:


Mr Sandeep Singh Sikarwar Nikhil
Dept. of CSE 211566
B.Tech. CSE

Dept. of CSE
INDEX

Sr. No. Experiment Name Page No.


Writing problem statements for systems of
1. 3-5
relevance
To perform requirement analysis and develop
2. 6-10
SRS documents

3. To draw basic DFD for your project 11-15

4. Implement Use Case Diagram the project 17-18

5. To Implement Class and Object diagram 19-21


To draw state chart and activity diagram for the
6. problem statement 22-25

7. To draw sequence and collaboration diagram 26-28

8. Testing 29-32

9. Future Scope

Dept. of CSE
Lab 1

Aim: Writing problem statements for systems of relevance.

The problem statement for Chess Engine can be understand with the help of
following questions.
Q1. What is the problem that needs to be solved?
The problem to be solved in building an open-source chess engine is to
create a program capable of playing chess at a high level of proficiency.
This involves developing algorithms and heuristics that can efficiently
search through the vast number of possible moves and positions in a
game of chess, evaluate the strength of different positions, and select
the best moves to make. Additionally, the engine must be optimized for
performance to ensure that it can analyze positions quickly and
accurately, making it suitable for use in various applications such as game
analysis, computer chess competitions, and chess training tools.
Access to the source code provides a valuable resource for students,
hobbyists, and aspiring developers to learn about chess programming,
algorithms, and software development practices. It serves as a practical
example for studying and understanding complex systems. Overall, the
purpose of making a chess engine open source is not only to solve the
problem of creating a proficient engine but also to foster collaboration,
transparency, community engagement, education, and accessibility.

Q2. Why is it a problem?


The development of a proficient chess engine, like Stockfish,
represents a significant problem due to several complex challenges
inherent in the game of chess and the nature of computer programming:
1. Complexity of Chess: Chess is a highly complex game with an
astronomical number of possible positions and moves. The branching
factor (number of possible moves in a given position) in chess is
Dept. of CSE
exceptionally high, leading to an exponential growth in the number of
possible positions as the game progresses.
2. Algorithmic Complexity: Designing algorithms that can effectively
search through the immense number of possible moves and positions
while efficiently pruning unpromising branches is a non-trivial task.
3. Performance Optimization: Achieving competitive performance
requires optimizing the engine to analyze positions quickly and
accurately.
4. Continuous Improvement: Chess engine development is an ongoing
process that requires continuous refinement and enhancement.
Keeping pace with advancements in chess theory, computer
hardware, and software engineering practices demands a dedicated
effort from a community of developers committed to the project's
long-term sustainability.

Q3. Where is the problem observed?


The problem is observed in several areas due to the prevalence of paid
chess engines like Komodo, Houdini, and others
1. Cost Barrier: Paid chess engines often come with a significant cost
barrier, limiting access to high-quality chess analysis and gameplay for
individuals who cannot afford expensive software licenses.
2. Closed Source Limitations: Closed-source chess engines restrict
access to their underlying algorithms, implementation details, and
source code.
3. Dependency on Commercial Interests: Paid chess engines are often
developed and maintained by commercial entities driven by profit
motives.
4. Inequality of Access: The prevalence of paid chess engines
exacerbates inequality of access to chess analysis tools and resources.
5. Limited Community Engagement: Closed-source chess engines
typically have limited community engagement and collaboration
opportunities.

Dept. of CSE
Q4. What kind of issues/problems can be overcome/solved using this project?
The development of an open-source chess engine like Stockfish
can help overcome or solve various problems and issues in several
domains:
1. Chess Education and Training: Chess engines provide valuable tools
for players of all skill levels to improve their game. Beginners can use
them to learn basic tactics and strategies, while advanced players can
analyze their games to identify strengths, weaknesses, and areas for
improvement. By making the engine open source, developers can
customize it to create educational resources tailored to different skill
levels and learning objectives.
2. Game Analysis and Study: Chess enthusiasts, coaches, and analysts
often use engines to analyze games, study openings, and explore new
variations.
3. Research in Artificial Intelligence: Chess engines serve as
benchmarks and testbeds for research in artificial intelligence and
machine learning. The algorithms and techniques developed for chess
programming can be applied to other domains, such as optimization,
decision-making, and pattern recognition. Open-source engines
provide researchers with access to state-of-the-art algorithms and
codebases, facilitating collaboration and innovation in AI research.
4. Fostering Transparency and Collaboration: Open-source
development promotes transparency by making the engine's source
code accessible to everyone.
5. Accessibility and Inclusivity: Chess engines democratize access to
high-level chess analysis and play by providing free, open-source
software that anyone can use and contribute to.
6. Software Engineering and Development Practices: Contributing to an
open-source project like a chess engine provides valuable experience
in software engineering and development practices.

Dept. of CSE
Lab 2
Aim: To perform requirement analysis and develop SRS documents.

1. Introduction

1.1 Purpose
The purpose of this document is to outline the requirements for the
development of an open-source chess engine. The engine aims to provide a
competitive level of chess play, incorporating adaptive properties, advanced
evaluation techniques, and community-driven development.
In the current project, the objective is to develop an open-source chess
engine that addresses the complexities and challenges inherent in computer
chess programming. The primary goal is to create a chess-playing program
capable of competing at a high level while incorporating adaptive properties
to improve its performance over time.

1.2 Scope
The project will involve conducting a literature survey, proposing an
algorithm based on the findings, developing and implementing the chess
engine, and integrating adaptive properties for continuous improvement.
The software will be released as open-source, encouraging collaboration
and contribution from the chess community.

1.3 Customers
The primary stakeholders for this project include chess enthusiasts, players,
coaches, and developers within the chess community. The project aims to
address their needs for a high-quality, open-source chess engine that offers
competitive gameplay and fosters collaboration and innovation.

Dept. of CSE
2. Functional Requirements
2.1 Move Generation
 The engine shall be capable of generating legal moves for a given
chess position.
 It shall consider the rules of chess, including piece movements,
capturing, and special moves such as castling and pawn promotion.
2.2 Position Evaluation
 The engine shall evaluate the strength of a given position based on
advanced evaluation techniques.
 Evaluation criteria shall include material balance, piece activity, pawn
structure, king safety, and positional advantages.
2.3 Search Algorithm
 The engine shall implement a search algorithm (e.g., minimax with
alpha-beta pruning or iterative deepening ) to explore the game tree
and select the best move.
 It shall incorporate optimization techniques to improve search
efficiency, such as transposition tables and parallel processing.
2.4Adaptive Properties
 The engine shall incorporate adaptive properties to learn and
improve its gameplay strategy over time.
2.5 User Interface
 The engine shall provide a user-friendly interface for interacting with
the program.
2.6 Integration with External Software
 The engine shall be compatible with external chess GUIs and
protocols, such as Universal Chess Interface (UCI) or Chess Engine
Communication Protocol (CECP).

Dept. of CSE
3. Non-Functional Requirements
3.1 Performance
 The engine shall analyze positions quickly and accurately, with
competitive performance against other chess engines.
 It shall optimize resource usage and scalability to handle deep
positions and complex endgames efficiently.
3.2 Robustness
 The engine shall be robust against errors, handling edge cases and
unexpected inputs gracefully.
 It shall undergo extensive testing to ensure correctness and reliability
under various conditions.
3.3 Portability
 The engine shall be compatible with multiple platforms and
architectures, including Windows, macOS, Linux, x86, and ARM.
 It shall utilize cross-platform libraries and tools to facilitate portability
and maintainability.
4. Constraints
 The project shall adhere to legal and ethical standards, including
compliance with chess federations' rules and regulations.

4. Platform
The chess engine shall be developed to run on multiple platforms, including
Windows, macOS, and Linux. It should be compatible with various
architectures, such as x86 and ARM, to ensure broad accessibility.

5. Stakeholder Requirements
 Developers:
 coding standard: C++ coding style defined by .clang-format.

Dept. of CSE
 version control: git and github.
 Users:
 ease of installation and download.
 multilingual documentation.
 Chess Community:
 educational resource: chessprogramming wiki.

6. Development Responsibility
I would be developing the software and I am responsible for the creation
of test cases documentation and other related part of the software.
7. Glossary
 UCI: Universal Chess Interface, a protocol for communication between
chess engines and graphical user interfaces.
 CECP: Chess Engine Communication Protocol, a standard for
communication between chess engines and graphical user interfaces.

8. Idea Discussion
The idea for the project originated from the desire to provide an
accessible, high-quality chess engine to the community.

9. Deliverables
The deliverables for the project include

 Source code
 User interface design
 Test cases.
 Documentation

Dept. of CSE
10. Risk Management
10.1 Risk Identification
Potential risks for the project include technical challenges in
algorithm design and implementation, resource constraints,
community engagement issues, and legal or ethical considerations.

10.2 Risk Mitigation


Risk mitigation strategies include conducting thorough research
and planning, collaborating with the community on Stockfish
Discord Server for feedback and support, allocating resources
effectively, and adhering to legal and ethical guidelines.
11. Scheduling and Estimates
The project will follow an agile development approach with iterative planning,
development, and review cycles.

Milestone Description Release Date Release


Iteration
M1 SRS Document 13-04-2024 R0
Completion

12. Technical Process


1. C++ compiler
2. git
3. github

Dept. of CSE
Lab 3

Aim: To draw basic DFD for your project.

Theory
DFD (Data Flow Diagram) is a visual representation of data flows within a
software system. In this representation, processes are depicted as bubbles or
rectangles, with data stores as parallel lines or rectangles and data
sources/destinations as squares.
DFDs can be used for modelling the logical and physical aspects of a system,
and they are useful for understanding system requirements, improving
communication between development teams and stakeholders, and identifying
potential bottlenecks.
Advantages:
1. DFDs provide a clear and concise representation of data flows within a
system.
2. DFDs help identify and analyse system processes, inputs, outputs, and
data stores.
3. DFDs are easy to understand, even for non-technical stakeholders.
4. DFDs can help identify potential problems, bottlenecks, and areas for
improvement.
5. DFDs can be used to document system requirements, design, and
implementation.
Disadvantages:
1. DFDs can be time-consuming to create and maintain.
2. DFDs may not be suitable for complex systems with multiple
interdependent processes.

Dept. of CSE
3. DFDs may oversimplify the system and ignore important details or
nuances.
4. DFDs may not be able to represent some types of data flow, such as
asynchronous or real-time data flows.
5. DFDs may not be suitable for systems that are constantly changing or
evolving.

Common Example:
Level 0 DFD:

Dept. of CSE
Level 1 DFD:

Level 2 DFD:
1. Game Configuration System

Dept. of CSE
2. Chess board Management System

3. Moves Management System

Dept. of CSE
4. A.I.

5. Game Report

Dept. of CSE
6. Chess Board

Dept. of CSE
Lab 4
Aim: Implement Use Case Diagram for your project.

Theory:
The use case diagram shows what actions a user can take and how they can
interact with the program. It also shows the consequences of doing certain
actions, where they would lead you to and what is included in performing an
action.

Advantages:
 Communication: Use case diagrams help to communicate the
requirements and functionalities of the system to stakeholders.
 Easy to understand: They are easy to understand for non-technical
stakeholders.
 Focus on user requirements: Use case diagrams focus on user
requirements and help to ensure that the system meets those
requirements.
 Scenarios: They provide a clear understanding of different scenarios in
which the system will be used.
Disadvantages:
 Limited detail: Use case diagrams provide a high-level overview of the
system and may not provide enough detail for complex systems.
 Time-consuming: Developing use case diagrams can be time-consuming
and may require multiple iterations.
 Ambiguity: The use case diagram may not provide a clear understanding
of the system if there is ambiguity in the requirements.
 Complexity: Use case diagrams can become complex if the system has
many actors and use cases.
In conclusion, use case diagrams are a useful tool for modelling the interactions
between actors and the system.

Dept. of CSE
Use case Diagram

Dept. of CSE
Lab 5

Aim: Implementing a class and object diagram.

Theory:
The class diagram is the way to depict the relationships between various
modules of any system. Here, we see about the classes and the relationship
involved in School Management System.

Classes:
 square_t: represent square in a chess board
 Move: represent a move in chess.
 board_state_t: represents board state like halfmove count, castling rights
and en passant possible square.
 board_t: represents a board. Has all the functions required for
maintaining a chess board position.
 Engine: represents an entity which is responsible for generating best
moves.
 UCI: this is main class which handle the user input and display output.

Attributes

 Square_t:
o Rank: vertical marking of chess board i.e. a,b,c,d etc.
o File: horizontal marking of chess board i.e. 1,2,3 etc.
 Move: from, to, promotion, capture, en_passant

Dept. of CSE
 Board_state_t: rights, ep_sq, halfmove_count
 Board_t: board, turn, white_king, black_king, board_state
 Engine: board, start_time, best_move, limits
 UCI: board, engine, thread

Methods

 Square_t:
o Inbound: return if the sq is valid
 Board_t:
o Is_sq_attacked_by: return if the square is attacked by any piece of
given color
o Generate_psuedo_legal_moves: generate moves according to
simple rules but doesn’t check if the move will leave the king in
check
 Engine:
o Iterative_deepening: call the alpha beta search algorithm with
increasing depth
o Absearch: main alpha beta search algorithm
 UCI:
o Process_command: process user input and call the appropriate
function

Dept. of CSE
Class Diagram

Dept. of CSE
Lab 6

Aim: To draw state chart and activity diagram for the problem statement.

State Chart

1. State chart diagram is used to describe the states of different objects in


its life cycle. Emphasis is placed on the state changes upon some internal
or external events. These states of objects are important to analyse and
implement them accurately. State chart diagrams are very important for
describing the states.
2. A state diagram, also known as a state machine diagram or state chart
diagram, is an illustration of the states an object can attain as well as the
transitions between those states in the Unified Modelling Language
(UML).
3. State chart diagrams describe the flow of control of an object. State
represents a situation during the life of an object in which it satisfies some
condition, performs some action, or waits for some event to occur. Each
state has a name. Rectangles with rounded corners are used to represent
states.

Dept. of CSE
Dept. of CSE
Activity Diagram

1. An activity diagram shows business and software processes as a


progression of actions. These actions can be carried out by people,
software components or computers. Activity diagrams are used to
describe business processes and use cases as well as to document the
implementation of system processes.

2. An activity diagram is a type of Unified Modelling Language (UML)


flowchart that shows the flow from one activity to another in a system or
process. It's used to describe the different dynamic aspects of a system and
is referred to as a 'behaviour diagram' because it describes what should
happen in the modelled system.

3. It may contain action nodes, control nodes, or object nodes. The control
flow of activity is represented by control nodes and object nodes that
illustrates the objects used within an activity. The activities are initiated
at the initial node and are terminated at the final node.

Dept. of CSE
Dept. of CSE
Lab 7

Aim: To draw sequence and collaboration diagram.

Theory:

A Sequence diagram is an interaction diagram that details about the


operation that is carried out. The sequence diagram captures the
interaction between the objects in the context of collaboration.
Sequence diagrams are time focused and they show the order of the
interaction visually by using the vertical axis of the diagram to
represent time.

Collaboration Diagram represents the interaction of the objects to


perform the behaviour of a particular use case or a part of use case. The
designers use the Sequence diagram and Collaboration Diagrams to
define and clarify the roles of the objects that perform a particular flow
of events of a use case.

Similarities Between Sequence and Collaboration Diagram

1. In Unified Modelling Language both the sequence diagram and


collaboration diagram are used as interaction diagrams.
2. Both the diagrams detail about the behavioural aspects of the system.

Dept. of CSE
Sequence diagram for making a normal move

Sequence diagram for pawn promotion

Dept. of CSE
Sequence diagram for castling king

Collaboration diagram

Dept. of CSE
Lab 8

Aim: Testing of the Software


Theory
Unit Testing is a type of software testing that focuses on individual units or
components of a software system. The purpose of unit testing is to validate
that each unit of the software works as intended and meets the requirements.
Unit testing is typically performed by developers, and it is performed early in
the development process before the code is integrated and tested as a whole
system.
Unit Testing is a software testing technique by means of which individual
units of software i.e. group of computer program modules, usage procedures,
and operating procedures are tested to determine whether they are suitable
for use or not.
Unit Testing is typically performed by the developer.

Objective of Unit Testing:


The objective of Unit Testing is:
1. To isolate a section of code.
2. To verify the correctness of the code.
3. To test every function and procedure.
4. To fix bugs early in the development cycle and to save costs.
5. To help the developers to understand the code base and enable them
to make changes quickly.
6. To help with code reuse.

Unit Testing Techniques


There are 3 types of Unit Testing Techniques.

Dept. of CSE
1. Black Box Testing: This testing technique is used in covering the unit
tests for input, user interface, and output parts.
2. White Box Testing: This technique is used in testing the functional
behaviour of the system by giving the input and checking the
functionality output including the internal design structure and code
of the modules.
3. Gray Box Testing: This technique is used in executing the relevant test
cases, test methods, test functions, and analysing the code
performance for the modules.

Testing input, output

Dept. of CSE
Modules Testing

Testing moves generation module

Testing castling rights modules

Testing make move and unmake move module

Dept. of CSE
Complete software test

Strategic Test

Dept. of CSE
Lab 9
Aim: Future Scope
Future Scope
1. Performance Optimization
Despite current optimizations, there may still be room to improve the
engine's efficiency, particularly in terms of search speed and evaluation
accuracy.
Potential Improvements: Investigate more advanced search algorithms,
parallelization techniques, or hardware acceleration to further enhance
performance.

2. Evaluation Function Refinement


Reason: The accuracy of the evaluation function directly impacts the
engine's playing strength. Even small improvements in evaluation can lead
to significant gains.
Potential Improvements: Experiment with new evaluation features, fine-
tune existing parameters, or explore machine learning techniques to learn
from game data and improve evaluation accuracy.

3. Endgame Tablebases Integration


Reason: Endgame tablebases can significantly improve the engine's
endgame play by providing perfect information for certain positions.
Potential Improvements: Integrate endgame tablebases into the engine to
handle endgame positions more accurately, potentially improving its
winning and drawing capabilities in such positions.

4. Neural Network Evaluation


Reason: Neural networks have demonstrated strong performance in chess
position evaluation, potentially surpassing handcrafted evaluation functions.
Potential Future Work: Develop and train neural network-based evaluation
functions tailored to the engine's needs, potentially leveraging
reinforcement learning techniques for self-improvement.

Dept. of CSE

You might also like